0

I'm using this code to remove an element

function deleteMyElement(id) {
    var elem = document.getElementById("myElement" + id);
    elem.remove();
}

It works fine for chrome and firefox but not for ie. The console shows me an error: The object does not support the remove method.

How can I get this working in all common browsers?

1 Answer 1

5

By doing it the normal way.

elem.parentNode.removeChild(elem);

.remove is a jQuery method, not JavaScript.

EDIT: Apparently, it's planned to be a JavaScript method. Kind of daft in my opinion, but there you go. Since it's experimental, it is not necessarily supported in all browsers.

Sign up to request clarification or add additional context in comments.

4 Comments

It's not just a jQuery method, but it's both experimental and not supported in all browsers.
@AnthonyGrist Ah, fair enough, thanks for the link :)
@AnthonyGrist, your link says it's not supported in IE. But it works now
@blckbird The code you were originally using isn't supported (which is why it didn't work and you asked this question), the code in this answer is supported (which is why it works for you).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.