I have a list:
<ul id="links_list" class="links_list">
<li id="296" class="sidebar_link">text
<a onclick="deleteLink(296)" href="javascript:void(0);">Delete Link</a>
</li>
<li id="297" class="sidebar_link">text2
<a onclick="deleteLink(297)" href="javascript:void(0);">Delete Link</a>
</li>
... etc for a long list of items ...
</ul>
I'm currently able to remove the first element using this:
function deleteFirst() {
... do ajax stuff ..
$('ul.links_list li:first-child').fadeTo("fast", 0.01, function(){ //fade
$(this).slideUp("fast", function() { //slide up
$(this).remove(); //then remove from the DOM
});
});
}
How can I modify this function to allow me to delete any item in the list?
$("anything #id")is a tremendously inefficient selector, and doesn't address any of the issues here. An ID selector should be only$("#ID").