How to create a div element in jQuery?

jQueryWeb DevelopmentFront End Technology

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>
</div>
$(".div").on("click",function(){
$('#box').append(
  $('<div/>')
    .attr("id", "newDiv1")
    .addClass("div")
    .append("<span/>")
      .text("hello world")
    );
});
raja
Published on 11-Dec-2017 08:16:28
Advertisements