0

I have a DOM element that can be accessed with JavaScript using

rectangle=document.getElementsByTagName("rectangle")[index];

I am trying to remove it from the DOM, using jQuery, as follows.

element=jQuery('rectangle').get(index);
element.remove();

However Firebug returns the error

TypeError: element.remove is not a function

1 Answer 1

3

$.get returns a standard DOMElement. Create a jQuery object from it and then $.remove will work.

element=jQuery(jQuery('rectangle').get(index));
element.remove();

Better yet, do this in one step and use $.eq instead of $.get:

element=jQuery('rectangle').eq(index);
element.remove();
Sign up to request clarification or add additional context in comments.

2 Comments

Or just element=jQuery('rectangle').eq(index) (without having to wrap it with jQuery() :)
You're welcome! If this answer helps you, please don't forget to accept it via clicking the check to the left.

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.