jQuery如何删除"id"从HTML内容的一部分 [英] JQuery how to remove "id" from a part of html content
本文介绍了jQuery如何删除"id"从HTML内容的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做这样的事情:
var html = $("#media").html();
$("#multimedia-content").append(html);
$("#multimedia-content").filter("*").removeAttr("id");
第三行失败,我想从html的这一部分中删除所有ID,但我不知道如何进行选择.
The 3th line fails, I want to remove all id's from this part of html but I don't know how to do the selection.
谢谢!
推荐答案
我个人想尝试一下:
$('#media') // grab the media content
.clone() // make a duplicate of it
//.find('*') // find all elements within the clone
.removeAttr('id') // remove their ID attributes
//.end() // end the .find()
.appendTo('#multimedia-content'); // now add it to the media container
如果您还希望#media丢失其ID,请删除.find()
和.end()
行,否则请取消注释.
If you'd like #media to lose its ID as well, remove the .find()
and .end()
lines, otherwise un-comment them.
这篇关于jQuery如何删除"id"从HTML内容的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文