Forum Moderators: open
<head><style type="text/css">
#style1 {background-color:yellow}
#style2 {background-color:pink}
</style>
<script>
<!--
function newid(){
document.getElementsByTagName('body')[0].id="style2"}
// -->
</script></head><body id="style1">
If I have <body id="style1"><br />
<a href="javascript:newid()">how</a> can I select the body tag and change the id to, for example, style2? <br />
</body>
supercool, thanks! What I tried was sticking
document.getElementsByTagName('body')[0].id="style2" into an onclick. It seems that without the quotes around style2 it fails.
<head><style type="text/css">
#style1 {background-color:yellow}
#style2 {background-color:pink}
#style1 p{width:300px;height:50px;border:2px solid
#000;position:absolute;top:60px;left:100px}
#style2 p{width:100px;border:5px solid #000;position:absolute;top:150px;left:300px}
</style>
<script>
<!--
function newid(){
document.getElementsByTagName('body')[0].id="style2"}
// -->
</script></head><body id="style1">
If I have <body id="style1"><br />
<a href="#" onclick="javascript:newid()">how</a> can I select the body tag and change theid to, for example, style2? <br />
<p>ioend</p>
</body>
Cool stuff, that javascript.