Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  58] [ 3]  / answers: 1 / hits: 25936  / 11 Years ago, sun, march 24, 2013, 12:00:00

I have a canvas object that loads on my page dynamically from a jQuery plugin. It has no wrapper, no id or class associated to it. But I need to remove it after



$(window).resize(function)() {...} 


takes place. I have tried using jQuery's



...next().remove(); 


technique, so that the neighboring div element can remove it from the DOM, but I am getting issues. specifically, additional elements on my page are also getting removed. Is there a healthy way to about this?



Thanks!


More From » jquery

 Answers
6

If you are not using multiple canvas elements, simply



$('canvas').remove();


Will remove all matched elements on the page. http://jsfiddle.net/vj6NP/



If you do have multiple canvas on the page and would like to remove only one, you could select which one to remove using nth-of-type.



For example to remove the first instance http://jsfiddle.net/vj6NP/3/: -



$('canvas:nth-of-type(1)').remove();

[#79392] Friday, March 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reed

Total Points: 725
Total Questions: 85
Total Answers: 89

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;