This question has already been answered, but I think that a simpler, simpler way to achieve the same goal would be to rely on the similarities between the jQuery selector model and CSS and just do:
$("#a, #b").click(function () {});
I often use this and have never seen it not working (I cannot talk about jQuery versions prior to 1.3.2, although, as I did not test it). Hope this ever helps someone.
UPDATE: I just re-read the stream and missed the comment you made that the specified nodes were already saved for variables, but this approach will still work with one minor tweek. you will want to do:
var a = $("#a"); var b = $("#b"); $(a.selector+", "+b.selector).click(function () {});
One of the great things jquery does is that it adds some special jQuery properties to the returned node (a selector, which is the original selector used to capture that node is one of them). You may run into some problems with this if your selector already contains commas. Maybe it's also possible if it's easier than just adding add, but its an interesting example of how cool jquery can be :).
The Brawny Man Dec 04 '09 at 16:22 2009-12-04 16:22
source share