Do you want to be a good Web Developer?

Enter Your Email To Get Our Exclusive Tutorials
And Offer Right In Your Email

jQuery Add and Remove

jQuery Add and Remove

jQuery provides many methods to elements from webpage to add new elements we use mainly append(), prepend(), after(), before() etc and for removing elements from webpage we use remove(), empty() etc.



To Add Elements


append()

It is used to insert the content at the end of the selected element.


$("a").append("This is some extra text here.");

                           or

$("a").append("<p>This is some extra text here</p>");




prepend()

It is used to insert the content at the beginning of the selected element.


$("a").prepend("This is some extra text here.");

                           or

$("a").prepend("<p>This is some extra text here</p>");



after()

It is used to insert the content at the after the selected element.


$("a").after("This is some extra text after the element.");



before()

It is used to insert the content at the before the selected element.


$("a").after("This is some extra text before the element.");


To Remove The Elements


remove()

It is used to remove the selected element and all its childrens


$("#para1").remove();



empty()

It is used to empty all the children present in the element.


$("#div1").empty();
PreviousNext

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email