Reputation: 9779
I want to remove an li
element from a ul
list.
i'm using old fashion java script with chrome and IE 9/10.
the java script code is pretty straight forward
document.getElementById(someid).remove();
This works perfectly in chrome but IE (version 10.0.92) gives me the following error
"Object doesn't support property or method 'Remove'"
How can I dynamically remove the an li
element from the list ?
Upvotes: 0
Views: 67
Reputation: 53228
You need to call removeChild()
on the parentElement
. For example:
document.getElementById(someid).parentElement.removeChild(document.getElementById(someid));
Alternatively, you can use JavaScript's prototyping to add a remove()
function:
Element.prototype.remove = function()
{
this.parentElement.removeChild(this);
}
This can then easily be called using your initial code:
document.getElementById(someid).remove();
Upvotes: 4