I have an on click function that toggles a class.
$(".main").click(function() {
$(this).toggleClass("classA classB");
$(".secondary").toggleClass("classC classD");
));
I need to add开发者_JAVA技巧 a check which class is triggered and add an action based on it, something like.
if ( class == 'classA') {
// do A
} else {
// do B
}
Can it be done with jQuery?
You can use .hasClass()
$(".main").click(function() {
$(this).toggleClass("classA classB");
$(".secondary").toggleClass("classC classD");
if ( $(this).hasClass('classA')) {
// do A
} else {
// do B
}
));
精彩评论