javascript - How does .add() work -


is method used add new element? or misuderstanding. how work?

     <div class="firstdiv">       text in first div      </div> 

after run following :

$( ".firstdiv" ).add( "p" ).text("new paragraph"); 

the browser shows new paragraph, text in first div goes?

thanks

the .add() method used add elements current selection , docs here

usage:

var $collection = $('div').add('p'); 

$collection contains div elements , p elements in document


Comments