A summary of jquery techniques

Source: Internet
Author: User

Because the main or responsible for the backend, so the front-end a lot of things are unfamiliar, jquery as the web development necessary skills, there are a lot of knowledge points, always remember not clear, so in this side to tidy up.

1. Execute after loading the page

$ (function() {    // program segment })

2. Click events

$ ("#xxx"). Click (function() {        // program segment    })

3. Add class to the element or change class

$ ("#xxx"). AddClass ("Class1");
// Click Time to change the style $ ("#aaa"). Click (function() {     $ ("#xxx"). Toggleclass ("Class1");  });

4. Assigning values to the css,html attribute of an element

$ ("#xxx"). CSS ("Display", "block");
$ ("#xxx"). HTML ("This is html<br/> the is HTML");

5. Get a jquery element

var a=$ ("#xxx"); // get the jquery object with ID xxx var b=$ (". xxx"); // Get the JQuery object class xxx

6. Get the value of an object

$ (". xxx"). Val (); // the value of the text box or drop-down box is $ (". XXX"). html (); // HTML content of the object var sex=$ ("#radio1"). Is (": Checked")? " Male ":" Female "; // the value of the Radio1 var marry=$ ("#checkbox1"). Is (": Checked")? " Married ":" Unmarried "; // The value of the check box

7. Selector

//Basic Selector$ ("#table1 tr:nth-child (even)"). AddClass ("Trodd");$("#divOne"). Val ()//element with ID divone$ (". Divone"). Val ()//class is an element of Divone$ ("div span"). Val ()//The span element under the DIV, which is separated by a space, indicates a subordinate element$ (". Class1. Class2"). Val ()//Class is the class2 element of class Class1, as above$ ("#divClass, span"). Val ()//the relationship with the ID divclass or the span element, which is either comma-represented or//Hierarchy Selector$ ("div span"). Val ();//all spans under the Div, ancestors and descendants, regardless of the layers nested, as long as the div under the span is selected$ ("Div>span"). Val ();//Div Under the first layer of span, parent-child relationship, note only the first-level span is selected. $ ("#divMid + div"). Val (); $ ("#divMid"). Next ("Div"). Val ();//Next div element with ID divmid$ ("#divMid ~ Div"). Val (); $ ("#divMid"). Nextall ("Div"). Val ();//all DIV elements after the ID is divmid$ ("#divMid"). Siblings ("Div"). Val ();//adjacent div element with ID divmid

A summary of jquery techniques

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.