Initial JQuery and jquery initialization Loading

Source: Internet
Author: User

Initial JQuery and jquery initialization Loading

JQuery syntax structure

JQuery statements mainly contain three parts: $ (), doucment, and ready ().

These three parts are called factory functions, selectors, and methods in JQuery.

$ () = JQuery ()

When the $ () parameter is a DOM object, this object does not need to be enclosed in double quotation marks. If you get a doucment object, write $ (doucment ).

 

$ (Function () {$ ("li "). mousemove (function () {callback (this).css ("background", "red ");}). mouseout (function () {iterator (this).css ("background", "") ;})}) Automatic Iteration

DOM object and JQuery object Conversion

// Onload = function () {// var $ dom = $ ("# myid"); // var dom = $ dom [0]; // dom. onclick = function () {// if (dom. checked = true) {// alert ("successful ");//}//}//}

You can convert a DOM object to a JQuery object to use the rich functions provided by JQuery, convert a JQuery object to a DOM object, and use the functions provided by the unique members of the DOM object.

JQuery Selector

Basic Selector

It mainly includes: Tag selector, class selector, ID selector, Union selector, intersection selector and global selector.

$ ("P"). click (function (){

$ ("Span" ).css ("background", "# FF6 ")

});

Level selector:

Child selector, child selector, adjacent selector, and peer selector.

$ ("H2"). click (function (){

$ ("# Menu span" ).css ("background", "# FF6 ");

});

When you click the h2 element, add the background color of # FF6 to the span element under # menu.

$ ("H2"). click (function (){

$ ("Body span" ).css ("background", "# FF6 ");

$ ("Body> span" ).css ("background", "# FF7 ");

});

Attribute Selector

$ ("H2"). click (function (){

$("H2 [title]" ).css ("background", "# FF6 ");

});

When you click the h2 element, you can add a background color of # FF6 to the h2 element containing the attribute name title.

Basic filter Selector

: First select the first element

: Last selects the last element

: Even Selects all elements with an even index (index starts from 0)

: Odd Selects all elements with an odd index (index starts from 0)

: Gt (index) Select the element whose index is greater than index (index starts from 0)

: Eq (index) selects the element whose index is equal to index (index starts from 0)

: Lt (index) Select the element whose index is smaller than index (index starts from 0)

: Header Selects all header elements, such as h1-h6

: Focus: select the element for which the current focus is obtained.

$ ("Tr: even" ).css ("background-color", "# F63 ");

Visibility filter Selector

: Visible: select all visible elements

: Hidden Selects all hidden elements

$ (Function () {$ ("p "). click (function () {$ ("p: hidden "). show (); $ ("p: visible "). hide (); $ ("li: even" ).css ("background-color", "# CCC"); $ (". s ").css (" background-color "," # FF99CC ") ;})) Visibility filter Selector

 

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.