Hackerss.com

hackerss
hackerss

Posted on

Crear dinamicamente divs in Javascript

Crear dinamicamente divs - Javascript:


//create a div element
const div = document.createElement('div');

//add a class to the div
div.classList.add('my-div');

//add an id to the div
div.id = 'my-div';

//add a text node to the div
div.appendChild(document.createTextNode('Hello World'));

//add the div to the body
document.body.appendChild(div);

Enter fullscreen mode Exit fullscreen mode

Latest comments (0)