jQuery :not Filters
The :not() filter can be used to find elements that do not match a particular selector type. For example, say you want to select row of a table except the first row, you can do it using$("tr:not(:first)")
You can use :not() with any of the jQuery filters and with most jQuery selectors. As another example, to find every link that does not begin with http://referencedesigner.com, you can write this:
$('a:not([href^="http://referencedesigner.com"])')
Aa a practical example you may like to highlight the first row of a Table with a pink background color and other rows using a different background color. We use not selector to select all rows other than the first row
<html> <head> <script type="text/javascript" src="jquery-1.8.0.min.js"></script> <script> $(document).ready(function(){ $("tr:first").css("background-color", "pink"); $("tr:not(:first)").css("background-color", "gainsboro"); }); </script> <body> <h1>List of Cars </h1> <table border=1> <tbody> <tr> <td>Make</td> <td>Model</td> </tr> <tr> <td>Toyota</td> <td>Corolla</td> </tr> <tr> <td>Honda </td> <td>Civic</td> </tr> <tr> <td>Ford </td> <td>Focus</td> </tr> </tbody> </table> </body> </html> |
You may like to try this example here.