Basic Filter Selector usage in jquery

Source: Internet
Author: User

This example describes the basic filter selector usage in jquery. Share to everyone for your reference. Specifically as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112-113 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/> <title> base filter selector </title> <style type=" Text/css "> #main {width:600px; border:1px Solid Green; Margin:auto; padding:10px; #tbl {border-collapse:collapse; border-top:1px solid red; border-left:1px solid red; margin:auto;} #tbl td{width:60px; height:60px; Border-collapse:collapse; border-bottom:1px solid red; border-right:1px solid red; } </style> <script src= "jquery-1.6.2.min.js" type= "Text/javascript" ></script> <script type= " Text/javascript "> $ (function () {//============= example 1========================//:first Description: Matches the first element found//....<1 > Modify the background color of the first cell//var $tds = $ ("#tbl Td:first"); $tds. CSS ("BackgroundColor", "Blue"); ....<2> modifies the background color of the first row//var $trs = $ ("#tbl Tr:first"); //$trs. CSS ("BackgroundColor", "Blue"); ============= Example 2========================//:last Description: Matches the last element found. Corresponds to: A. ...<1> modifies the background color of a subsequent cell//var $tds = $ ("#tbl td:last"); $tds. CSS ("BackgroundColor", "Blue"); ============= example 3========================//:not (selector) removes all elements that match a given selector. A bit like "non"//...<1> Modifies the text of all columns that are not tdclass//var $tds = $ ("#tbl td:not (. tdclass)"); $tds. Text ("Not Tdclass"); ============= Example 4========================//:even Description: Matches all elements with an even number of index values, counting from 0. The array of JS is counted starting from 0. For example, to select a row in a table, because it is counted from 0, the first TR in the table is even 0. ...<1> the rows with an even number of index values into yellow//var $trs = $ ("#tbl Tr:even"); $trs. CSS ("BackgroundColor", "yellow"); ============= example 5========================//: Odd description: Match all index values to odd-numbered elements, and: even corresponds, counting starting from 0. var $trs = $ ("#tbl tr:odd"); $trs. CSS ("BackgroundColor", "yellow"); ============= Example 6========================//:eq (Index) Description: An element that matches a given index value. EQ (0) is the first TR element. The parentheses contain the index value, not the number of element permutations. ...<1> sets the background color of the second cell//var $tds = $ ("#tbl td:eq (1)"); $tds. CSS ("backgRoundcolor "," Gray "); ============= Example 6========================//:gt (Index) Description: Matches all elements that are greater than the given index value. ...<1> sets the background color of all cells with subscript index greater than 1 to gray//var $tds = $ ("#tbl td:gt (1)"); $tds. CSS ("BackgroundColor", "Gray"); ============= Example 7========================//:lt (Index) Description: Matches all elements that are less than the given index value. ...<1> sets the background color of all cells with subscript index less than 3 to gray var $tds = $ ("#tbl td:lt (3)"); $tds. CSS ("BackgroundColor", "Gray"); ============= examples 8========================//:header (fixed notation) Description: match the title elements such as H1, H2, H3, and so on. This is a TITLE element specifically designed to get H1,H2. ...<1> all the H-tag background color to modify var $hs = $ (": Header"); $hs. CSS ("BackgroundColor", "gold"); ============= example 8========================//slice get the subscript range element var $trs = $ ("#tbl tr"). Slice (1, 3); $trs. CSS ("BackgroundColor", "gold"); }); </script> </head> <body> <div id= "main" > <h1> I'm h1</h1> <h2>, I'm h2</h2>. <h3> I am h3</h3> <table id= "TBL" > <tr> <td>1</td><td>1</td><td> 1</td> </tr> <tr> <TD class= "Tdclass" >2</td><td>2</td><td>2</td> </tr> <tr> <td>3</ td><td>3</td><td>3</td> </tr> <tr> <td>4</td><td>4</ TD><TD class= "Tdclass" >4</td> </tr> <tr> <td>5</td><td>5</td> <td>5</td> </tr> <tr> <td>6</td><td>6</td><td class= "Tdclass" >6</td> </tr> </table> </div> </body> </html>

I hope this article will help you with your jquery programming.

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.