homepage Welcome to WebmasterWorld Guest from 50.19.144.243
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Remove id attribute
ocon




msg:4454145
 2:11 pm on May 16, 2012 (gmt 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="">?

 

Fotiman




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

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




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

Perfect, thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved