Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1009073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:52:11+00:00 2026-05-16T08:52:11+00:00

I am reading an online tutorial that says if the <script></script> is right on

  • 0

I am reading an online tutorial that says if the <script></script> is right on top of </body> the $(document).ready is not necessary b/c the document has been loaded at that moment.

Q1> Is that true?

Q2>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script src="jquery.viewport.min.js"></script>

<script>
$(window).scroll(function() { // this line will track all mouse scroll event

});
</script>

What does the $(window) mean? Is this a jquery selector? If it is, then the previous claim looks correct because we don’t have to include this inside

$(document).ready(function() {

});

Q3> why we use $link here? why we choose to use $link rather than var link?

<script>
$(window).scroll(function() {
  $link = $('nav a[hash=#first]');
  $link.addClass('selected');
});
</script>

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:52:12+00:00Added an answer on May 16, 2026 at 8:52 am

    Q1. Yes and no. Perhaps jQuery will still do a few things after the has been reached, but if you are just trying to find a element that was loaded previously in the body it will work.

    Q2. It creates a jQuery Object pointing to the window. It is not a jQuery Selector, neither is $(document) or $(document.body) – in these you are passing a node to jQuery and not a Selector.

    Q3. It caches it. By performing $link = $('nav a[hash=#first]'); we cache/assign the result to $link, as if we did $('nav a[hash=#first]') twice, then jQuery would have to find that result twice – this could become/will become quite intensive if all your calls are not cached. You should also be using var $link = $('nav a[hash=#first]');, to ensure that $link is not defined globally – as that is bad (due to variable conflicts).

    As a general practice; anything which uses DOM elements should be after document ready (to ensure they have loaded and jQuery is ready to use them), anything that doesn’t shouldn’t (as there is no need for the wait).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'v been reading through the Apple Docs, read through a couple tutorials online, and
Ok, so I was reading the Java online tutorial for generics and I found
I have been reading a number of articles online suggesting different approaches to migrate
I'm starting out with Lift and been reading a few tutorials and books that
I have been trying to learn from reading tutorials online and stuff but I
I've been reading online about the pros and cons of using static methods for
I need some help using Linq to xml, I've been reading online articles but
I'm learning Java by reading the online Java book, but im finding it hard
I'm looking for some advice on how to go about reading the online documentation
After searching online and reading the Oracle documentation for this, I need some help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.