jquery - how to remove parent if child has specific text? -
i wanted remove parent div if child has specific text:
<div> <span>test</span> </div> <div> <span>text</span> </div>
in above code want remove div contains test. tried lot filter function,but thinking wrong concept. best way remove this?
so, how detect text tested or not?
try using has() contains-selector - used contains since said contains - if want check exact match can't use it
$('div').has('span:contains(test)').remove()
demo: fiddle
for exact match
$('div span').filter(function(){ return $.trim($(this).text()) == 'test'; }).parent().remove()
demo: fiddle
Comments
Post a Comment