home

Jquery add() Method

Jquery Add() Methods sets the expression within the matched elements. Jquery add(selector) method adds another elements to an existing(matched with given selector) bunch of elements. and in the below we have simple example code of add() method.

$(selector).add(element)
  <div>Div Element</div>
  <p>P element</p>
  <span>Span element</span>
<script>
   $("div").add("p").add("span").css("background", "red");
</script>

Jquery .remove() Method

Jquery remove() method removes the selected element including all text and children element

$(selector).remove(element)
//html code here
<div>div element will be removed after clicking on button including this text and all so 
child element of this div, <p>this child node of the div</p></div> //javascript code <script> $("button").click(function(){ $(div).remove(); }); </script>

Jquery .empty() Method

$(selector).remove(element)

empty () method can remove only content from the element(in our case inside p element text will be hide).

<script>
  $("button").click(function(){
    $("div").empty();
});
</script>

<p>if you click on button paragraph text going to hide</p>

Jquery .detach() Method

$(selector).detach(element)

detach () method removes everything like including selected element and text and also event.

<script>
  $("button").click(function(){
    $("div").detach();
});
</script>

<p>if you click on button div tag going to hide</p>