How to create a div element in jQuery?

They are many way to add a div using jquery , but as the requirement says  on click of any square we have to addd a div.  The following code below will help in adding a div on click 

Click on any square below to see the result
 <div id='box'>    
       <div class = "div" style = "background-color:blue;"></div>
       <div class = "div" style = "background-color:green;"></div>
       <div class = "div" style = "background-color:red;"></div>
    .attr("id", "newDiv1")
      .text("hello world")

Updated on: 12-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started