* Using jQuery
Did you mean that you want to delete everything with the same identifier? (This is how I interpreted the question)
$('#id').remove()
(remember that using the same identifier on multiple DOM elements is not considered good programming and should always be avoided! Always use a good IDE to encode your code)
You can also delete using a class (this is the best way to remove grouped items by class name)
$('.className').remove()
These two functions remove ALL elements with identifier / class. To limit the removal of id / class'es only from LI
$('li #id').remove(); $('li .className').remove();
You can also make a function in JavaScript. This will remove any DOM by clicking on the itemDelete element.
$('.itemDelete').live("click", function() { var id = $(this).parent().get(0).id; $("#" + id).remove(); });
Do a loop and call a function?
function deleteLI(id) { $("#" + id).remove(); };
source share