Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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> </div>
$(".div").on("click",function(){
$('#box').append(
$('<div/>')
.attr("id", "newDiv1")
.addClass("div")
.append("<span/>")
.text("hello world")
);
}); Advertisements
