Summary of some jQuery features and usage

Source: Internet
Author: User

1. Precise and simple object selection (dom ):
Copy codeThe Code is as follows:
$ ('# Element'); // equivalent to document. getElementById
("Element ")
$ ('. Element'); // Class
$ ('P'); // html tag
$ ("Form> input"); // sub-Object
$ ("Div, span, p. myClass"); // select multiple objects at the same time
$ ("Tr: odd" ).css ("background-color", "# bbbbff"); // table
Background
$ (": Input"); // form object
$ ("Input [name = 'newsletter ']"); // a specific form object

2. The application of object functions is simple and unlimited:
Copy codeThe Code is as follows:
Element. function (par );
$ ("P. surprise"). addClass ("ohmy"). show ("slow ")...

3. Operations on selected objects (including styles ):
Copy codeThe Code is as follows:
$ ("# Element"). addClass ("selected"); // Add a style to the object
Certificate ('{element'}.css ({"background-color": "yellow", "font
-Weight ":" bolder "}); // Changes the object style.
$ ("P"). text ("Some new text."); // change the object text
$ ("Img"). attr ({src: "test.jpg", alt: "Test Image"
}); // Change the object text
$ ("P"). add ("span"); // add a label to the object
$ ("P"). find ("span"); // find the corresponding elements in the object
$ ("P"). parent (); // parent element of the object
$ ("P"). append ("<B> Hello </B>"); // add content to the object

4. Support for aJax and file formats: xml/html/script/json/jsonp
Copy codeThe Code is as follows:
$ ("# Feeds"). load ("feeds.html"); // imports static page content in the corresponding region
$ ("# Feeds"). load ("feeds. php", {limit: 25}, function ()
{Alert ("The last 25 entries in the feed have been
Loaded ") ;}); // import Dynamic Content

5. event support:
Copy codeThe Code is as follows:
$ ("P"). hover (function (){
$ (This). addClass ("hilite"); // move the cursor over it
}, Function (){
$ (This). removeClass ("hilite"); // move the mouse away
}); // Different effects (automatically loop all p objects)
)

6. Animation:
Copy codeThe Code is as follows:
$ ("P"). show ("slow"); // hide an object (slow gradient)
$ ("# Go"). click (function (){
$ ("# Block"). animate ({
Width: "90% ",
Height: "100% ",
FontSize: "10em"
},1000 );
}); // Dynamic changes in width, height, and font after clicking the mouse

7. Extension:
Copy codeThe Code is as follows:
$. Fn. background = function (bg ){
Return this.css ('background', bg );
};
$ (# Element). background ("red ");

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.