JavaScript-test jQuery and javascriptjquery

Source: Internet
Author: User

JavaScript-test jQuery and javascriptjquery
Test the JavaScript Framework library-jQuery

Reference jQuery

To test the JavaScript library, you must reference it on the webpage.

To reference a library, use the <script> tag. Set the src attribute to the library URL:

Reference jQuery




<Script src = "https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</Script>






JQuery description

The main jQuery function is the $ () function (jQuery function ). If you pass a DOM object to this function, it returns the jQuery object with the jQuery function added to it.

JQuery allows you to use the CSS selector to select elements.

In JavaScript, you can assign a function to handle window loading events:

JavaScript:

Function myFunction ()
{
Var obj = document. getElementById ("h01 ");
Obj. innerHTML = "Hello jQuery ";
}
Onload = myFunction;

The equivalent jQuery is different:

JQuery:

Function myFunction ()
{
$ ("# H01" ).html ("Hello jQuery ");
}
$ (Document). ready (myFunction );

In the last line of the code above, the html dom document Object is passed to jQuery: $ (document ).

When you pass a DOM object to jQuery, jQuery returns the jQuery object packaged with an html dom object.

The jQuery function returns a new jQuery object, where ready () is a method.

Since a function is a variable in JavaScript, you can pass myFunction as a variable to jQuery's ready method.

JQuery returns the jQuery object, which is different from the passed DOM object.
The attributes and methods of a jQuery object are different from those of a DOM object.
You cannot use html dom attributes and methods on jQuery objects.

Test jQuery

Please try the following example:

Instance

 




<Script src = "https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</Script>
<Script>
Function myFunction ()
{
$ ("# H01" ).html ("Hello jQuery ")
}
$ (Document). ready (myFunction );
</Script>


 

Please try this example again:

Instance

 




<Script src = "https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</Script>
<Script>
Function myFunction ()
{
$ ("# H01"). attr ("style", "color: red" ).html ("Hello jQuery ")
}
$ (Document). ready (myFunction );
</Script>


 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.