+ 1
Scanning through html table with javascript
I would like to make some kind of iteration in javascript where it loops through a table and checks every cell for a specific class. if it is class A it does something, and if it is class B it would do something different. Could someone please help me with this :/
2 ответов
+ 3
From question "test if an element contains a class": [edited]
https://stackoverflow.com/a/5898748
element.classList.contains() and related without using jQuery
Here's the indexOf method from that answer:
function hasClass(element, class) {
return (' ' + element.className + ' ').indexOf(' ' + class+ ' ') > -1;
}
Aside: By polyfills for older browsers, the answer means:
https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills
The "DOM & Events" DOM4 polyfill seems to support classList.
0
nice, alright! 😃 thanks!