Welcome to WebmasterWorld Guest from 54.196.176.3

Forum Moderators: open

Message Too Old, No Replies

Remove id attribute

     

ocon

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

5+ Year Member Top Contributors Of The Month



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="">?

Fotiman

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

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



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.

ocon

3:37 pm on May 16, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month



Perfect, thanks!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month