Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Select element class (pure Javascript) – is this correct?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #150488
    Rugg
    Participant

    Is this proper syntax for selecting elements by class using pure javascript?

    Select elements with class name test

    document.getElementsByClassName('test');
    

    Select first element with class name test

        document.getElementsByClassName('test').firstChild;
    

    Select the body element

       document.body
    

    ALSO, Any way to select html,body together?

    #150584
    whatsoever
    Participant

    You can select html and body using document.querySelectorAll(‘html, body’). Keep in mind that it is supported on IE8+, Chrome 1+, FF3.5+, Opera 10+ and Safari 3.2+

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.