473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Dynamically changing the id attribute of body tag

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>
Jul 23 '05 #1
2 1611
On 21 Oct 2004 11:11:03 -0700, jdi <a_*******@hotmail.com> wrote:
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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
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?

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now...
6
by: mayurkoul2002 | last post by:
hello there..... i have a problem here...........i want to assign ID attribute dynamically to the html tags......and i need a function for tht....can anybody help me out in tht
3
by: ICPooreMan | last post by:
The following is a very simple example of what I want to do take an elements oncontextmenu and changing it dynamically onclick of that same element. The code below will fail unless you change the...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.