Dynamically changing the id attribute of body tag

J

jdi

I'm trying to change the value of the id attribute of the page's
<body> tag AFTER the tag is outputted.

i've two ways and both don't work

1)
document.getElementById("body").setAttribute("id", "hello");

2)
document.getElementsByTagName("body")[0].setAttribute("id","hello");

My page is as follows:

<html>
....
....
<body id="body">
....
</body>
</html>
 
M

Michael Winter

I'm trying to change the value of the id attribute of the page's
<body> tag AFTER the tag is outputted.

Might I ask why?

I can't see any reason why you might want to. The BODY element is unique
within a document, so why should it need a unique identifier.

Mike
 
L

Lee

jdi said:
I'm trying to change the value of the id attribute of the page's
<body> tag

I could well be overlooking something, but it seems to me that
when you find yourself in the situation of wanting to change the
id of *any* tag, it's time to reassess your approach.
If it's the id of the <body> tag, that seems even more likely.

What are you trying to accomplish?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top