Currently working on enhancing some JavaScript/jQuery code by storing selectors in variables when they are used more than once to improve performance, for example:
var element = $("#element");
element.hide();
However, I am facing difficulties while trying to chain these cached selectors. Below is my attempt:
var element1 = $("#element1");
var element2 = $("#element2");
$(element1, element2).show();
This approach seems to work only for the first cached element and not the second one. Any suggestions on the correct syntax for chaining multiple cached selectors?
I have researched it but couldn't find a solution!