如何使用Jquery/JavaScript完全删除canvas元素? [英] How to completely remove the canvas element with Jquery/JavaScript?

查看:1788
本文介绍了如何使用Jquery/JavaScript完全删除canvas元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个canvas对象,该对象从jQuery插件动态加载到我的页面上.它没有包装器,没有与之关联的id或类.但我需要在

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)() {...} 

发生.我尝试使用jQuery的

takes place. I have tried using jQuery's

...next().remove(); 

技术,以便相邻的div元素可以将其从DOM中删除,但是我遇到了问题.具体来说,我页面上的其他元素也将被删除.有健康的方法吗?

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?

谢谢!

推荐答案

如果您不使用多个画布元素,只需

If you are not using multiple canvas elements, simply

$('canvas').remove();

将删除页面上所有匹配的元素. http://jsfiddle.net/vj6NP/

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.

例如删除第一个实例 http://jsfiddle.net/vj6NP/3/ :-

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

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

这篇关于如何使用Jquery/JavaScript完全删除canvas元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆