开发者

JQuery how to remove "id" from a part of html content

开发者 https://www.devze.com 2023-03-17 23:23 出处:网络
I want to do something like this: var html = $(\"#media\").html(); $(\"#multimedia-content\").append(html);

I want to do something like this:

var html = $("#media").html();
$("#multimedia-content").append(html);
$("#multimedia-content").fil开发者_如何学运维ter("*").removeAttr("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.

Thanks!


Personally, i would try this:

$('#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

If you'd like #media to lose its ID as well, remove the .find() and .end() lines, otherwise un-comment them.


You should do:

$("#multimedia-content *").removeAttr("id");

This will remove all the ids of the elements inside #multimedia-content


Try this:

$("*[id], #multimedia-content").removeAttr("id");

This way it only removes the id attribute from elements that contain the id attribute.


To remove any id attributes from any child elements of #multimedia-content:

$("#multimedia-content").find().each(function() {
    $(this).removeAttr("id");
});
0

精彩评论

暂无评论...
验证码 换一张
取 消