Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create dynamic div in javascript without using jquery?

Tags:

javascript

dom

I want to make dynamic division on button click on my web page please tell me easiest solution, I am new to JavaScript.

like image 626
Android Programmer Avatar asked Jul 05 '26 01:07

Android Programmer


2 Answers

Hope this will help

function divcreate() {
    var div = document.createElement("div");
    div.setAttribute("id", "mydiv");
    div.className = "mdiv";
    div.style.display = "none";
    document.body.appendChild(div);
}
like image 127
MR. Kumar Avatar answered Jul 06 '26 13:07

MR. Kumar


To create an element, use the createElement method

var mydiv = document.createElement('div');
//mydiv is a variable containing a newly created div
like image 33
Joseph Avatar answered Jul 06 '26 15:07

Joseph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!