If you have an element with two classes applied to it, how can you check what the second class was?
For example:
class="class1 abc"
class="class1 xyz"
When class1 is clicked, how can you check what the second class was, so you can redirect to appropriate action?
$('.class1').click(function() {
// ** var secondClass = abc | xyz
// ** do something if second class was abc, or something else if second class was xyz **
$('.class1').click(function() {
if ($(this).hasClass('abc')) {
//...
} else {
//...
}
});
You could use hasClass()
..
$('.class1').click(function() {
if($this.hasClass("xyz")){
...
} else {
...
}
});
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