Basic jQuery knowledge, jquery

Source: Internet
Author: User

Basic jQuery knowledge, jquery

 

The upgraded version of JS framework encapsulates JS.

 

File Suffix:. min. js min compressed version

 

Method: The script label src = "jquery" must be loaded at the top.

Element searching

Var a = document. getElementById ("aa ");
Alert ();
Var a = document. getElementsByClassName ("a1 ");
Alert (a [2]);
Document. getElementsByTagName ("div ");
Var a = document. getElementsByName ("uid ");
Alert (a [0]);

Operation content
Non-standard single element
Alert (a. innerText); text
Alert (a. innerHTML); HTML code
Form Element
Alert (a. value );
A. value = "hello ";

Operation attribute
A. setAttribute ("test", "test ");
A. removeAttribute ("test ");
Alert (a. getAttribute ("value "));

Operation Style
A. style. fontSize = "30px ";
Alert (a. style. color );

Unified operation Element
Var d = document. getElementsByClassName ("a1 ");
For (var I = 0; I <d. length; I ++)
{
D [I]. style. fontSize = "30px ";
}


Element searching
Var a = $ ("# aa ");
Alert ();
Var a = $ (". a1 ");
Alert (a. eq (2 ));
Var a = $ ("div ");
Var a = $ ("[bs = 1]");
Alert ();

Operation content
Non-form Element
Alert (a. text ());
A. text ("bbbbb ");
Alert(a.html ());
Form Element
A. val ("hello ");

Operation attribute
A. attr ("test", "test ");
A. removeAttr ("test ");
Alert (a. attr ("value "));
A. prop ("test", "test ");
A. removeProp ("test ");
Alert (a. prop ("test "));

A. prop ("checked", true );
Alert (a. prop ("checked "));

Operation Style
A.css ("background-color", "green ");
Alert(a.css ("width "));

Unified operation Element
$ (". A1" ).css ("font-size", "30px ");
$ (". Ck"). prop ("checked", true );

Event
$ ("# Ck"). click (function (){

Alert ($ (this ));
$ (This) select its own element

$ (". Ck"). prop ("checked", $ (this). prop ("checked "));

}) Anonymous Functions

$ (". Ck"). click (function (){
Alert ("bb ");
})
In the event method, $ (this) selects its own element.

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.