简体   繁体   中英

Trying to remove element from DOM using jQuery

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

$.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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM