javascript - Search for matching LI items in separate UL -
i'm trying figure out how find 'li' items matching text in 2 different 'ul's when user clicks button can removed. button appended each 'li' , can text , remove original item. 'li' sortable , user can add more, can't done locations of 'li's.
right have (i've removed things make more understandable):
javascript:
$("li") .prepend("<span class='ui-icon'></span>") $(".ui-icon") .click(function() { var itemtext = $(this).closest("li").text(); $(this).closest("li").fadeout(200, function() { $(this).remove(); }); $("li:contains(itemtext)").remove(); //the part i'm having trouble })
html:
<ul id="items"> <li> <h3 id="title">title1</h3> <p id="body">body1</p> </li> <li> <h3 id="title">title2</h3> <p id="body">body2</p> </li> <li> <h3 id="title">title3</h3> <p id="body">body3</p> </li> <li> <h3 id="title">title4</h3> <p id="body">body4</p> </li> </ul> <ul id="favs"> <li> <h3 id="title">title2</h3> <p id="body">body2</p> </li> <li> <h3 id="title">title3</h3> <p id="body">body3</p> </li> <li> <h3 id="title">title1</h3> <p id="body">body1</p> </li> <li> <h3 id="title">title4</h3> <p id="body">body4</p> </li> </ul>
$(".ui-icon") .click(function() { var item = item.closest("li"); var itemtext = item.text(); var parentul = item.closest("ul"); item.fadeout(200, function() { item.remove(); }); parentul.siblings('ul').find("li:contains(" + itemtext + ")").remove(); //the part i'm having trouble })
i think you're looking for. makes sure except 1 you're fading out removed.
as aside, id
s should unique.
Comments
Post a Comment