dom - Using jQuery, how do you select an element that is a child of $(this)? -


rough html structure:

<div class="wrapper">   <p></p>   <p></p>   <p></p> </div> <div class="wrapper">   <p></p>   <p></p>   <p></p> </div> <div class="wrapper">   <p></p>   <p></p>   <p></p> </div> 

assuming have function this:

$('div.wrapper').each(function() {     // more stuff }); 

i want things like:

$(this).('p:eq(2)').remove(); 

or

$(this).('p:contains("old text")').text('new text'); 

starting $(this) want select child elements inside of it.

you can do:

$('div.wrapper').each(function() {     $('p:eq(2)', this).remove(); }); 

which uses this container or parent relative element want find.

or

$('div.wrapper').each(function() {     $(this).find('p').eq(2).remove(); }); 

which uses .find() same thing above.

jsfiddle example


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -