Do u know the difference between jquery $(document).ready and $(window).load ???

Discussion in 'Programming' started by lionel.web, Dec 17, 2015.

to remove all ads.
  1. lionel.web

    lionel.web Member

    Messages:
    98
    I thought, that there is no difference between these two. That both work and do stuff,
    when the page has loaded. WRONG!!!
    $(document).ready work when the DOM is ready.
    That means that can be executed even when the pictures have NOT been loaded, cause the DOM is ready (the structure of the page and its elements)
    But, when you need to do something, when EVERYTHING has loaded,
    comes the $(window).load.
    I found it out, when i needed to pass a javascript variable at the start of the page, and do something with that. I made it with $(document).ready and $(window).load

    I found also this relative article. Check it out!
    https://4loc.wordpress.com/2009/04/28/documentready-vs-windowload/
     
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,675
    'window' is the top level object that contains the 'document object', which contains the page elements.

    Not understanding such basics is one of the problems with the way that so many people think that "jquery" is all that is ever needed.
     
  3. lionel.web

    lionel.web Member

    Messages:
    98
    ok, sorry for posting this info to the forum.
    There is nothing to do with understanding. Is just a clarification for these two.
    I wont do it again!
    Everyone in here, know everything!
    No sharing info again!
     
  4. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,675
    My comment wasn't a dig at you, it was simply a general gripe about the 'popular' idea that no one ever needs to learn the basics of a programming or script language, and they can just jump in with an additional layer of complexity of a "framework" and hope "it just works". I saw another example yesterday at a different forum where the person was using "Bootstrap CSS" but did not know enough basic CSS to figure out why some radio buttons were truncating the caption text if it was too long for the container. Very few seem to grasp the idea that knowing the basics means not waiting several hours for somebody else to spoon feed an answer.

    It's a bit like them hoping to solve simultaneous equations before learning the "times tables".
     

Share This Page