Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to do something like this:

var html = $("#media").html();
$("#multimedia-content").append(html);
$("#multimedia-content").filter("*").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!

like image 533
Santiago Avatar asked Dec 16 '22 12:12

Santiago


1 Answers

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.

like image 74
Brad Christie Avatar answered Jan 05 '23 02:01

Brad Christie