You can’t do it with getElementsByClassName()
method instead use querySelectorAll()
method with comma separated class selectors.
document.querySelectorAll('.a,.b')
More Related Contents:
- How can I change an element’s class with JavaScript?
- Is there a spec that the id of elements should be made global variable?
- Converting HTML string into DOM elements?
- Check if an element contains a class in JavaScript?
- Chrome extension – retrieving global variable from webpage
- innerText vs innerHTML vs label vs text vs textContent vs outerText
- Get next / previous element using JavaScript?
- Why is the value of my input always empty if I store it in a variable?
- What is innerHTML on input elements?
- How to convert a DOM node list to an array in Javascript?
- Adding an onclick event to a table row
- Is there a DOM event that fires when an HTML select element is closed?
- Is innerHTML asynchronous?
- Does the onchange event propagate?
- Difference between Element.value and Element.getAttribute(“value”)
- Change ‘s option and trigger events with JavaScript
- Is there any “on DOM change” event? [duplicate]
- Why is the variable holding the input value always logged as empty?
- Can I apply CSS to the elements within an iframe?
- HTML DOM: Which events do not bubble?
- Changing the order of elements
- createElement vs. createElementNS
- Focus Input Box On Load
- Trying to set a span element equal to a variable value in a JS Rock, Paper, Scissors Game
- What is the difference between `firstChild` and `firstElementChild`?
- How can I get access to a Highcharts chart through a DOM-Container?
- How can I remove wrapper (parent element) without removing the child?
- Is there a cross-browser standard on-load event for HTML’s “object” tag?
- How to reduce the length of a video using JavaScript? [closed]
- Why I cant use jQuery functionality