I am new to javascript/jquery and I might not be aware of many functions that could help me with my problems as I have very elementary knowledge of javascript and jquery. And the project I am working on is just for practice.
So, I have a string which I want to compare with certain values, and three different values are possible which are mutually exhaustive.
$(".grid-item").click(function() {
var classname = $(this).attr('class');
console.log(classname); //This returns "grid-item active car-right"
var reg_class = /active checked booked/;
var what_class = classname.match(reg_class);
$(this).toggle_function(){
if(what_class == active){
}
if(what_class == checked){
}
if(what_class == booked){
}
}
});
But this wouldn't work as the match function compares the reg_class variable's value whole as a string, and there nothing like that in the classname variable.
I looked upon this answer, "Compare one String with multiple values in one expression". But I couldn't get my problem solved there.
So, how do I create a regex variable with three distinct possible values and then compare it with the value I have in variable classname.
Isn't there any way to compare like this: (if classname == %active%)........This might seem ridiculous but, I don't know if this can be done in javascript or not.