I am attempting to call a JavaScript function from jQuery. When I try to pass an argument to JavaScript function:
var brandRcObj = "b-brand-box";
$('.b-brand-box').on('mouseleave', function(){
brandOn(brandRcObj);
});
I am getting the following error:
"Uncaught Error: Syntax error, unrecognized expression: '.b-brand-box'"
I'm doing this because I will use the same mouseleave
event multiple times in my project. Therefore I wanted to write a JavaScript function as follows:
function brandOn(brandClass){
var classObj = "'" + "." + brandClass + "'";
var imgObj = "'" + "." + brandClass + " " + "img" + "'";
$(classObj).css({
backgroundColor: 'white',
opacity: 1
});
$(imgObj).css({
opacity: 1
});
}
Thanks for yor help!