For the first time, I got in this kind of unusual situtation
I have to select a div on which more than 2 classes are applied, that to in random order
For Example:
Assume that I have a <div> on which following 3 classes are applied content-text, right-align and bold-font. I need to select this div, but problem is that classes are applied in different order on different pages
<div class="content-text right-align bold-font">...</div>
<div class="right-align content-text bold-font">...</div>
<div class="content-text bold-font right-align ">...</div>
...
How can I select this particular div, no matter how classes are applied?
Thanks
Use the getElementsByClassName method to get elements by multiple class names, e.g. document. getElementsByClassName('box green') . The method returns an array-like object containing all the elements that have all of the given class names. Here is the HTML for the examples in this article.
Use the * selector to select all elements in a document.
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.
Use a comma to union multiple queries: var tds = $(this). find('input, textarea');
This will work fine. CSS selectors in general don't care about the order of classes, just the ones that are applied. This also goes for jQuery:
$('div.content-text.right-align.bold-font');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With