adv jquery

Posted on 2012-09-18
Last Modified: 2012-09-19
In Jquery I understand that the jq code is written and executed before the html page is loaded. Is that correct? so the javascript code is run after the jq.

What is the advantage of this. Can there be an example..
Question by:Moizsaif123
    LVL 7

    Assisted Solution

    LVL 81

    Expert Comment

    > Is that correct?

    No, if you put you jQuery inside the head section, it will run before loading of the body content.

    Else check the links provided by aplusexpert
    LVL 4

    Author Comment

    >> it will run before loading of the body content.

    is this why jq can access or manipulate html elements like <p> and <a> tags whereas javascript cannot...
    LVL 81

    Accepted Solution

    again jQuery is Javascript.

    to manipulate body content, so element like like <p> and <a>
    you need to wait the loading of the body, its element... else the box is empty, you can't play with the toys inside

    most of time we use :
    window.onload = function() {
       // now we can play with body content with pure javascript code or jQuery

    Open in new window

    or with jQuery :
    $(document).ready(function() {
       // now we can play with body content with pure javascript code or jQuery

    Open in new window
    LVL 4

    Author Comment

    this is just for reference purpose....

     window.onload = function(){ alert("welcome"); }

    Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is that the HTML 'document' isn't finished loading yet, when you first try to run your code.

    To circumvent both problems, jQuery has a simple statement that checks the document and waits until it's ready to be manipulated, known as the ready event:

       // Your code here
    LVL 81

    Expert Comment


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    CFFILE upload help 98 88
    ajax, jquery and web method in 46 50
    placing image in table cell with jquery 5 37
    Alert not firing 2 22
    by Julian Matz As of jQuery ( 1.4 the .live() method ( supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
    In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now