Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Post is document.body to be deprecated?

    I have noticed that in many cases:

    document.getElementsByTagName('body')[0]
    or
    document.documentElement

    seems to work better than
    document.body

    Now, what do u think/know: Is it a trend to replace the document.body as the document referece?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, I doubt it'll be deprecated. However, it only exists in HTML DOM, and then only if the document is HTML, not if the document is XHTML. Most things that are typically bound to document.body actually belong on the document.documentElement. (as seen in the differences in ie6 in standards mode versus earlier versions or ie6 in quirks mode)

    It's not a good generic way of accessing that element, and use of it is discouraged.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    If so... which is the best probable future way to stabilize the document reference?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    document.documentElement will always reference the root element of the document, if that's what you're asking for. It depends a bit on what you want to do.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    well. hm... for instance

    document.documentElement.event

    it looks like

    document.documentElement.onmousemove = function(){showMousepos(event)}
    woun't work as i was expected to...

    For the moment i use

    <body onmousemove="showMousepos(event)">

    to be sure that it will works crossbrowser...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var body = document.getElementsByTagName('body')[0];
    
    body.onmousemove = function ....
    It's only the shortcut reference "document.body" that's gone; you just need to create a new one (assuming that body, and not documentElement, is what you want; which in this case it is).
    Last edited by brothercake; 03-17-2005 at 01:59 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •