How do I check if all children, or all selectors, have same class?
The class is unknown…
<script>
$(document).ready(function() {
var symbols = $("div:first-child").attr("class");
if ($("div").hasClass(symbols).length == 3) {
console.log("same");
};
});
</script>
<div class="john"></div>
<div class="john"></div>
<div class="john"></div>
This doesn’t work… :-/
If any of the divs are not class john this will find them, then you check the length and if it’s not zero then some exist.
This is a problem:
It will return the entire class string, but the div could have more than one class, and all will be returned. But when you check with either my code or
hasClassyou can only send in one class, not a bunch together.