- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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") ); });
- Related Articles
- How to create div dynamically using jQuery?
- How to scroll to element in horizontal div using jQuery?
- How to wrap tables with div element using jQuery?
- How to get the width of a div element using jQuery?
- How to get the height of a div element using jQuery?
- How to create wrapper div around two other divs with jQuery?
- How to duplicate a div using jQuery?
- How to load a page in div using jQuery?
- How to toggle a div visibility using jQuery?
- How to copy the content of a div into another div using jQuery?
- How to replace innerHTML of a div using jQuery?
- How to print div content using jQuery?
- How to put a complete HTML page in a div using jQuery?
- How to replace innerHTML of a div tag using jQuery?
- How to get innerHTML of a div tag using jQuery?

Advertisements