JQuery official learning materials: Selection Elements

Source: Internet
Author: User

 

  • Select Element

 

  • Select an element by ID
"# MyId ");

 

  • Select elements through Class
". MyClass ");

 

  • Select an element through Attribute
"Input [name = 'first _ name']");

 

  • Select elements using the composite CSS Selector
"# Contents ul. people li ");

 

  • Pseudo Selector
$ ("A. external: first ");$ ("Tr: odd ");// Select # All input elements in myForm$ ("# MyForm: input ");$ ("Div: visible ");// Except the first three divs$ ("Div: gt (2 )");// All the divs that are currently animated.$ ("Div: animated ");

 

  • Selector Selection
// Search for all the <a> elements whose rel attributes end with "thinger"$ ("A [rel $ = 'thinger ']");
.

 

  • Determines whether the selector contains any element.
// This cannot be runIf ($ ("div. foo ")){...}
// Test whether the selector contains elements.If ($ ("div. foo"). length ){...}

 

  • Save Selector
Var $ divs = $ ("div ");

 

  • Refining and filtering Selector
// Refining Selector$ ("Div. foo"). has ("p"); // <p> tag contained in the div. foo Element$ ("H1"). not (". bar"); // No h1 element whose class is bar$ ("Ul li"). filter (". current"); // The class is the unordered list subitem of current.$ ("Ul li"). first (); // subitem of the first unordered list$ ("Ul li"). eq (5); // The sixth subitem.

 

  • Select form Element
"Form: button ");
"Form: checkbox ");
"Form: checked ");
"Form: disabled ");
"Form: enabled ");
"Form: file ");
"Form: image ");
"Form: input ");
"Form: password ");
"Form: radio ");
"Form input [name = 'gender']: radio ");
"Form: reset ");
"Form: selected ");
"Form: submit ");
"Form: text ");
Alternatively, you can use other optional methods that are better than adding a pseudo selector to a tag name or some other selector.

Related Article

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.