Welcome to WebmasterWorld Guest from 54.144.114.177

Forum Moderators: open

Message Too Old, No Replies

Remove id attribute

     
2:11 pm on May 16, 2012 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:222
votes: 0


If I have <div id="name1"> I can change the id to something else using:

<script>
document.getElementById("name1").id="name2";
</script>

What can I do if I just want to remove the id and just have <div>? Would I use:

<script>
document.getElementById("name1").id="";
</script>

Or would that just set the div to <div id="">?
2:28 pm on May 16, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4965
votes: 10


document.getElementById("name1").removeAttribute("id");

Setting id to an empty string will not remove the attribute. You can verify this by using browser tools like Firebug or Chrome's Developer Tool to inspect the element and you'll still see an empty id attribute defined.
3:37 pm on May 16, 2012 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:222
votes: 0


Perfect, thanks!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members