- 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
Found 8895 Articles for Front End Technology
![Nizam Techs](https://www.tutorialspoint.com/assets/profiles/12567/profile/60_109859-1514781067.png)
666 Views
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").on("click",function(){ $('#box').append( $('') .attr("id", "newDiv1") .addClass("div") .append("") .text("hello world") ); });
![David Meador](https://www.tutorialspoint.com/assets/profiles/13351/profile/60_165994-1512670078.jpg)
4K+ Views
To insert element as a last child using jQuery, use the append() method. The append( content ) method appends content to the inside of every matched element.ExampleYou can try to run the following code to learn how to insert element as a last child using jQuery:Live Demo jQuery Example var x = 0; $(document).ready(function() { $('.add').on('click', function (event) { var html = "demo text " + x++ + ""; $("#parent-div").append(html); }); }); .div{ margin:10px; padding:12px; border:2px solid #F38B00; width:60px; } Hello World
![David Meador](https://www.tutorialspoint.com/assets/profiles/13351/profile/60_165994-1512670078.jpg)
6K+ Views
To insert element as a first child using jQuery, use the prepend() method. The prepend( content ) method prepends content to the inside of every matched element.ExampleYou can try to run the following code to learn how to insert element as a first child using jQuery:Live Demo jQuery Example var x = 0; $(document).ready(function() { $('.add').on('click', function (event) { var html = "demo text " + x++ + ""; $("#parent-div").prepend(html); }); }); .div { margin:10px; padding:12px; border:2px solid #F38B00; width:60px; } Hello World
![David Meador](https://www.tutorialspoint.com/assets/profiles/13351/profile/60_165994-1512670078.jpg)
130 Views
To insert content after each of the matched elements using jQuery, use the after() method.The after( content ) method inserts content after each of the matched elements. Here is the description of all the parameters used by this method −content − Content to insert after each target. This could be HTML or Text contentExampleYou can try to run the following code to learn how to insert content after each of the matched elements:Live Demo jQuery after() method $(document).ready(function() { ... Read More
![Amit D](https://www.tutorialspoint.com/assets/profiles/13349/profile/60_63530-1512538715.jpg)
453 Views
To remove all CSS classes using jQuery, use the removeClass() method, with no argument.ExampleYou can try to run the following code to remove class:Live Demo jQuery Example $(document).ready(function() { $("p").removeClass(); }); .red { color:red; } .green { color:green; } This is first paragraph. This is second paragraph.
![Amit D](https://www.tutorialspoint.com/assets/profiles/13349/profile/60_63530-1512538715.jpg)
6K+ Views
To add table row in jQuery, use the append() method to add table tags.ExampleYou can try to run the following code to learn how to add table row in jQuery:Live Demo jQuery Add Table Rows table{ width: 100%; margin: 25px 0; border-collapse: collapse; } table, th, td{ border: 1px solid #6C220B; } table th, table td{ padding: 8px; text-align: left; } $(document).ready(function(){ $(".row").click(function(){ var name = $("#name").val(); var subject = $("#subject").val(); var markup = "" + name + "" + subject + ""; $("table tbody").append(markup); }); }); Choose Name Subject Amit Java
![Amit D](https://www.tutorialspoint.com/assets/profiles/13349/profile/60_63530-1512538715.jpg)
337 Views
There may be a situation when you would like to insert new one or more DOM elements in your existing document. jQuery provides various methods to insert elements at various locations.The after( content ) method insert content after each of the matched elements whereas the method before( content ) method inserts content before each of the matched elements.After contentThe after( content ) method inserts content after each of the matched elements.ExampleYou can try to run the following code to learn how to insert an element into DOM, with after() method:Live Demo jQuery after(content) method ... Read More
![Amit D](https://www.tutorialspoint.com/assets/profiles/13349/profile/60_63530-1512538715.jpg)
1K+ Views
To remove all the elements from DOM using element ID, use the remove() method.ExampleYou can try to run the following code to remove all the elements from DOM using element ID:Live Demo $(document).ready(function(){ $("button").click(function(){ $("#mydiv").remove(); }); }); Click to remove all elements This is some text. This is demo text.
![Amit D](https://www.tutorialspoint.com/assets/profiles/13349/profile/60_63530-1512538715.jpg)
778 Views
The empty() method removes all child nodes from the set of matched elements whereas the method remove() method removes all matched elements from the DOM.To remove an element, use the remove() method.ExampleYou can try to run the following code to learn how to remove an element from DOM using jQuery:Live Demo jQuery remove() method $(document).ready(function() { $("div").click(function () { $(this).remove( ); }); }); .div { margin:10px; padding:12px; border:2px solid #666; width:60px; } Click on any square below:
![Amit D](https://www.tutorialspoint.com/assets/profiles/13349/profile/60_63530-1512538715.jpg)
6K+ Views
To replace a DOM element with the specified HTML or DOM elements using jQuery, use the replaceWith() method. The replaceWith (content) method replaces all matched elements with the specified HTML or DOM elements. This returns the JQuery element that was just replaced, which has been removed from the DOM.ExampleYou can try to run the following code to learn how to replace a DOM element with the specified HTML or DOM element:Live Demo jQuery replaceWith() method $(document).ready(function() { ... Read More