Skip to main content
mention simpler
Source Link
rogerdpack
  • 67.7k
  • 40
  • 290
  • 409

Of course, all currentmodern browsers now support the following simpler way:

var elements = document.getElementsByClassName('someClass'); 

but be warned it doesn't work with IE8 or before. See http://caniuse.com/getelementsbyclassname

Also, not all browsers will return a pure NodeList like they're supposed to.

You're probably still better off using your favorite cross-browser library.

Of course, all current browsers now support:

var elements = document.getElementsByClassName('someClass'); 

but be warned it doesn't work with IE8 or before. See http://caniuse.com/getelementsbyclassname

Also, not all browsers will return a pure NodeList like they're supposed to.

You're probably still better off using your favorite cross-browser library.

Of course, all modern browsers now support the following simpler way:

var elements = document.getElementsByClassName('someClass'); 

but be warned it doesn't work with IE8 or before. See http://caniuse.com/getelementsbyclassname

Also, not all browsers will return a pure NodeList like they're supposed to.

You're probably still better off using your favorite cross-browser library.

added 6 characters in body
Source Link
Blazemonger
  • 93.3k
  • 28
  • 147
  • 181

Of course, all current browsers now support:

var elements = document.getElementsByClassName('someClass');

var elements = document.getElementsByClassName('someClass'); 

but be warned it doesn't work with IE8 or before. See http://caniuse.com/getelementsbyclassname

Also, not all browsers will return a pure NodeListNodeList like they're supposed to.

You're probably still better off using your favorite cross-browser library.

Of course, all current browsers now support:

var elements = document.getElementsByClassName('someClass');

but be warned it doesn't work with IE8 or before. See http://caniuse.com/getelementsbyclassname

Also, not all browsers will return a pure NodeList like they're supposed to.

You're probably still better off using your favorite cross-browser library.

Of course, all current browsers now support:

var elements = document.getElementsByClassName('someClass'); 

but be warned it doesn't work with IE8 or before. See http://caniuse.com/getelementsbyclassname

Also, not all browsers will return a pure NodeList like they're supposed to.

You're probably still better off using your favorite cross-browser library.

Source Link
ColdCold
  • 4.3k
  • 2
  • 28
  • 20

Of course, all current browsers now support:

var elements = document.getElementsByClassName('someClass');

but be warned it doesn't work with IE8 or before. See http://caniuse.com/getelementsbyclassname

Also, not all browsers will return a pure NodeList like they're supposed to.

You're probably still better off using your favorite cross-browser library.