2

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" thing...

Basically I'm just looking for an alternative too

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

2 Answers 2

2
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.

Sign up to request clarification or add additional context in comments.

4 Comments

Note that one two three and four can't be jQuery objects. (well, they can, but it will have unexpected results)
doubt, doesn't having something done in $(window) will automatically be done in $(document) too?
$(document).ready(function() //executes when HTML-Document is loaded and DOM is ready while $(window).load(function() { // executes when complete page is fully loaded, including all frames, objects and images
@user1145009 With the update, your question is now going to have unexpected results. this inside the each will instead be a jQuery object rather than the dom node. Not necessarily a problem if that's intended, but it's out of the ordinary.
2
$(window).add(document).doStuff();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.