Dynamically changing the id attribute of body tag

Discussion in 'Javascript' started by jdi, Oct 21, 2004.

  1. jdi

    jdi Guest

    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>
     
    jdi, Oct 21, 2004
    #1
    1. Advertising

  2. On 21 Oct 2004 11:11:03 -0700, jdi <> 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.
     
    Michael Winter, Oct 21, 2004
    #2
    1. Advertising

  3. jdi

    Lee Guest

    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?
     
    Lee, Oct 21, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    947
    John C. Bollinger
    Jan 27, 2006
  2. Mark Rae

    Add an attribute to the tag <body>?

    Mark Rae, Oct 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    346
    Gustavo Arriola
    Oct 31, 2006
  3. _Who
    Replies:
    4
    Views:
    875
  4. Replies:
    2
    Views:
    238
  5. Replies:
    7
    Views:
    177
    -Lost
    Apr 7, 2007
Loading...

Share This Page