How to create div element dynamically by using javascript | Learn javascript

Create div element dynamically using javascript

And if you want to want to create div element inside any other html element of page body then nothing to worry. Let's suppose we have a div in our page which id is testDiv like given below



and you want to create div inside this testDiv. Just you have to change the last line of CreateDivElement() function from


document.body.appendChild(divElement);
to
document.getElementById('testDiv').appendChild(divElement);

0 comments:

Post a Comment