Mujtaba Hussain Bhat Mujtaba Hussain Bhat - 1 year ago 61
Javascript Question

Trying add a div dynamically with giving class inside a div

i was trying to create a div dynamically by using js method createElement() in which i am giving a class but is not working

HTML code

<p>Click the button to make a BUTTON element.</p>

<button onclick="myFunction()">Try it</button>

function myFunction() {
var btn = document.createElement('<div class="test"></div>');

Answer Source

I think you want something like this:

function myFunction() {
    var btn = document.createElement('div');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download