All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

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 ❯