Somebody saw me using the following JQuery code:
function showAll(){
$(".button").show();
}
function hideAll(){
$(".button").hide();
}
And he said that this was a waste of resources. That I should first assign $(".button") to a variable, and then perform the show() and hide() methods on this variable like this:
var allButtons = $(".button");
function showAll(){
allButtons.show();
}
function hideAll(){
allButtons.hide();
}
Both versions work, but what is the performance benefit to this? I believe the benefit is negligible and, moreover, cumbersome because now you have another level of separation between the class name and the variable you're modifying, but does he have a valid point? Is one of the two considered best practice?