admin管理员组文章数量:1302382
I'm curious if anyone knows why this piece of jQuery code doesn't remove the images?
var a = $('#tblMain').clone().remove('img');
The table is being selected. This is trying to take the table on the webpage and export to excel but I do not want the images to export.
Thank you,
I'm curious if anyone knows why this piece of jQuery code doesn't remove the images?
var a = $('#tblMain').clone().remove('img');
The table is being selected. This is trying to take the table on the webpage and export to excel but I do not want the images to export.
Thank you,
Share edited May 23, 2011 at 15:11 Michael asked May 23, 2011 at 14:56 MichaelMichael 1522 silver badges13 bronze badges 2-
5
(img)
refers to a variable name, don't you perhaps want('img')
as a selector? – pimvdb Commented May 23, 2011 at 14:58 - Put your ment in as the answer! – Brian Seim at EvoDynamic Inc Commented May 23, 2011 at 15:02
2 Answers
Reset to default 5Do it like this:
$("#tblMain").clone().find("img").remove();
EDIT: Okay, here's the problem:
selector: A selector expression that filters the set of matched elements to be removed.
http://api.jquery./remove/
The img
in .remove('img')
is to filter the set of items in the jquery object, NOT to find elements within the items themselves. In this case, the jquery object contains only one item, the cloned table. Therefore, .remove('img')
removes nothing, since the jquery object does not contain any images (only images within items it contains).
I don't know what's happening behind the scenes, but you're referring to some variable called img
whilst you most probably just want to select all img
elements. In that case, you ought to use a selector as a string:
var a = $('#tblMain').clone().remove('img');
EDIT: .clone.remove
does not seem to work indeed. I used this workaround which actually works:
.find('img').each(function() {$(this).remove()});
本文标签: javascriptJQuery remove imagesStack Overflow
版权声明:本文标题:javascript - JQuery remove images - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741664915a2391250.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论