Common jquery operations

Source: Internet
Author: User

Id selector $ ("# jquery ");

Class selector $ (". jquery ");

Tag selector $ ("Div ");

Combination selector $ ("input. jquery [value = 'juqery ']");

Empty $. Trim ();

Iteration

$ (". Jquery"). Each (

Function (){

Console. Log ($ (this). Val ());

}

);

Obtain sub-element (optional)

$. (". Jquery"). Children ();

Obtain all child elements (selector required)

$ (". Jquery"). Find ("span ");

Use jsonp for cross-Origin

 
$. Ajax ({URL: "XXX", datatype: "jsonp", jsonp: "Callback", data: {X: x}, success: function () {alert ();}});

 

ServerCode

 
Public void login () throws ioexception {httpservletrequest request = getrequest (); httpservletresponse response = getresponse (); string callback = request. getparameter ("Callback"); printwriter writer = response. getwriter (); writer. print (callback + "(0)"); writer. close ();}

Trigger event

$ ("Input"). Trigger ();

Jquery registers page loading events

$ (Document). Ready (function (){

});

$ (Function (){

});

Bind event

 
$ ("Button"). BIND ("click", function () {$ ("p"). slidetoggle ();});
 
$ ("Button"). Click (function () {$ ("p"). slidetoggle ();});

$ (Document). On ('mouseover', '. wtf', function (){
$ (This). Show ();
});
Hide and display selected elements

$ ("# Input"). Toggle ();

Display Element
$ ("Input"). Show ();
Hide Element
$ ("Input"). Hide ();
Get value
$ ("# Input"). Val ();
Get innerhtml
$ ("# Input" pai.html ();
Obtains the value of the selected checkbox item.
$ ("Input: Radio [name = 'pushtype']: checked"). Val ();
Find parent Element
$ ("# A"). Parent ();
Remove Element
$ ("# A"). Remove ();
Remove clsss
$ ("# A"). removeclass ();
Set clsss

$ ("# A"). addclass ();
The control button is disabled: $ ("# BTN "). ATTR ({"disabled": "disabled"}); the control button is available $ ("# BTN "). removeattr ("disabled ");

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.