Reputation: 495
I want to trigger a delete of all LI within this UL if any of the LI contain stockTo.
This below, is not working.
var stockTo = 'abc';
$('ul#thelst li:contains(stock)').remove();
Upvotes: 1
Views: 3044
Reputation: 3065
hey the way you have written your jQuery is not proper..
check the live demo here. How to remove list
BELOW IS THE HTML
<div>
<ul id="thelst">
<li>test test test test 111 </li>
<li>test test test test 112 </li>
<li>test test test test 113 </li>
<li>test test test test 114 </li>
<li>test test test test 115 </li>
<li>test test test test 116 </li>
</ul>
</div>
THIS IS THE JQUERY CODE INSIDE DOCUMENT READY FUNCTION
var stockTo = '114';
$('#thelst').find("li:contains(" + stockTo + ")").remove();
EDIT DEMO 2 removing the list on click of anchor
Upvotes: 1
Reputation: 34107
Hiya demo http://jsfiddle.net/m7zUh/
It will be good to see how your HTML look like but see the code below.
In the sample example: Click on trigger button and you will see foo
will get removed as li
Hope this helps, :) have a good one, cheers
HTML
<div> sample</div>
<ul id="thelst">
<li>Hulk</li>
<li>Hawk</li>
<li>Foo</li>
<li>Bar</li>
<li>Rambo</li>
</ul>
<input type="button" id="trigger" value="trigger" />
Jquery code
$('#trigger').click(function() {
var stockTo = 'Foo';
$('ul#thelst li:contains(' + stockTo + ')').remove();
});
Upvotes: 1
Reputation: 337560
Try this:
var stockTo = 'abc';
$('ul#thelst li:contains(' + stockTo + ')').parent().children().remove();
Upvotes: 3