This note is just a handy note for me to learn JQuery. I have made some preparations and hope it will be of reference value to new users. 1. attribute: Set a calculated attribute value for all matching elements.
// Add the class = "btn" attribute to all inputs"
// $ ("Input"). attr ("class", "btn ");
2. CSS: add the specified class name for each Matching Element
// Add a style for all the submit buttons
$ ("Input: submit"). addClass ("btn ");
3. Value: Obtain the current value of the First Matching Element.
// Obtain the value of a button
// Alert ($ ("# Button1"). val ());
4. Html code: Obtain the html content of the First Matching Element. This function cannot be used in XML documents. But it can be used in XHTML documents.
// Output html code between p
// Alert ($ ("# p1" cmd.html ());
// Re-assign values to the html in the Div
// $ ("# P1" 2.16.html (" ");
5. Text: Obtain the content of all matching elements.
The result is a combination of text content contained by all matching elements. This method is effective for both HTML and XML documents.
// Output the text value between p
// Alert ($ ("# p1"). text ());
// Re-assign a value to the text in p
// $ ("# P1"). text ("100 ");
6. // select the radio button
$ ("# Select1"). val ("option 2 ");
// If ($ ("# select1"). val () = 'option 2 ')
//{
// Alert ("option 2 selected ");
//}
7. convert one or more DOM elements into jQuery objects
// Set the page background color
Certificate (document.body).css ("background", "# c0c0c0 ");
// Hide all elements in a form [unavailable]
// $ (P. elements). hide ();
8. In each usage, each matching element is used as the context to execute a function.
// $ ("Button"). click (function (){
// $ ("P"). each (function (index, domEle ){
/// DomEle = this
// Configure (domeleapps.css ("backgroundColor", "yellow ");
// If ($ (this). is ("# stop ")){
// $ ("Span"). text ("Stopped at p index #" + index );
// Return false;
//}
//});
//});
9. the return value of this function is consistent with the 'length' attribute of the jQuery object.
// Number of buttons
// Alert ($ ("input: submit"). size () + "and" + $ ("input: submit"). length );
10. obtain all the matching DOM element sets.
// Alert ($ ("input"). get (). reverse ());
// Obtain a matching element. Num indicates the number of matched elements.
// Alert ($ ("input"). get (1 ));
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