SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    When would this return FALSE?

    Hi all,

    I'm analysing some different scripts to learn more about JavaScript. One thing I've noticed in a few of them is the following piece of code:

    Code:
    if (document.getElementById && document.getElementsByTagName) {
       //stuff
       }
    When would this ever return FALSE? As long as the page has tags, I can't see how this could return FALSE, so why include it in the first place when the script is event-driven?

  2. #2
    SitePoint Addict CommanderZ's Avatar
    Join Date
    Apr 2006
    Location
    Czech Republic
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should test if the DOM structure is completely loaded or not. It would return false in case the structure was incomplete yet.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,815
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    It would return false if the person is using Internet Explorer 4, Netscape 4, or any other old browser that came out before those commands were introduced.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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