myFunc() is bound to the document scroll so it will be called a lot. I want to store the HTML selections in a var and pass them to the function. When I run my example below I get the console error Unable to get value of the property 'css': object is null or undefined.
var a1 = $('#a1');
var a2 = $('#a2');
$(document).bind("scroll", function() {
setTimeout(myFunc, 1000, a1, a2);
}
function myFunc(a1, a2) {
a1.css('color', 'blue');
a2.css('font-weight', 'bold');
}
How do I pass multiple jQuery selectors, stored in a variables, to a function?
1 Answer