Skip to content Skip to sidebar Skip to footer

How To Select Multiple Jquery Objects?

Like if I wanted to select both document and window elements. $(window, document).doStuff(); Doesn't work. Probably because according to the docs, 2nd argument is some 'context' t

Solution 1:

var one   = $("#1");
var two   = $("#2");
var three = $("#3");
var four  = $("#4");



 $([one, two, three, four]).each(function() {
        // your function here
    });

The document ready event executes already when the HTML-Document is loaded and the DOM is ready, even if all the graphics haven’t loaded yet.

If you want to hook up your events for certain elements before the window loads, then $(document).ready is the right place.

Solution 2:

$(window).add(document).doStuff();

Post a Comment for "How To Select Multiple Jquery Objects?"