jquery selector for new notes on the Web front end

Source: Internet
Author: User
Tags jquery library

 
$ (' img[alt] ')
② the custom selector;
In addition to the various CSS selectors, jquery adds unique, completely different custom selectors.
Most custom selectors in jquery allow us to select one or more elements from the elements that have been found. The syntax for custom selectors is the same as the pseudo-class selector syntax in CSS, with the selectors starting with a colon (:).
For example, I want to select the second item from the <div> collection with the horizontal class;
$ (' Div.horizontal:eq (1) ')
③ add a style to every alternate behavior table
Two very useful custom selectors in the jquery library are : Odd and : even;
    : Odd can change the style for even rows in a table;
    : Even instead, change the style for odd rows in the table;
Why use : even selectors for odd rows? Very simple: the EQ () selector,: Odd , and : Even selectors use JavaScript built-in numbering from 0, so the first line is numbered 0 (even), the second row is numbered 1 (odd), And so on
④:nth-child () Selector
    : Nth-child () is the only selector in jquery that counts from 1;
⑤ form-based selectors
    
[The above is simply a brief introduction to the selector expression, which will be discussed in the future.]
Iv. how DOM traversal?
In many cases, getting the parent or ancestor elements of an element is a basic operation, and this is where jquery and DOM traversal methods come in.
Without a filter function, you must iterate through each element and test them individually, but with the filter function below, you can still take advantage of the implicit iterative energy of jquery to keep an introduction to the code.
$ (' a '). Filter (function () {    return this.hostname && this.hostname! = location.hostname;}). AddClass (' external ');
The second line of code can filter out the <a> elements that meet the following two criteria.
1. You must include an HREF attribute with the domain name (this.hostname). This test can exclude mailto level similar links;
2, the link to the domain name (this.hostname) must not be moved to the name of the current domain of the page (Location.hostname);
More precisely, the. Filter () method iterates over all matching elements, invokes the incoming function on each element and tests the return value of the function, and if the function returns False, removes the corresponding element from the matching collection, and if True is returned, preserves the element.
  


       

  
  

jquery selector for new notes on the Web front end

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.