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.
Comments
Post a Comment