`

Custom selectors

阅读更多
Custom Selectors
To the wide variety of CSS and XPath selectors, jQuery adds its own custom selectors.
Most of the custom selectors allow us to pick certain elements out of a line-up, so to
speak. The syntax is the same as the CSS pseudo-class syntax, where the selector starts
with a colon (:). For example, if we wanted to select the second item from a matched
set of divs with a class of horizontal, we would write it like this:
   
 $('div.horizontal:eq(1)')

Note that the eq(1) gets the second item from the set because JavaScript array
numbering is zero-based, meaning that it starts with 0. In contrast, CSS is one-based,
so a CSS selector such as $('div:nth-child(1)') gets any div that is the first child
of its parent.
Styling Alternate Rows
Two very useful custom selectors in the jQuery library aredd and :even.
.odd {
  background-color: #ffc; /* pale yellow for odd rows */
}
.even {
  background-color: #cef; /* pale blue for even rows */
}


$(document).ready(function() {
  $('tr:odd').addClass('odd');
  $('tr:even').addClass('even');
});

分享到:
评论

相关推荐

    custom-selectors:一组通用的 CSS 自定义选择器

    $ npm install custom-selectors 示例, : --universal { box-sizing : border-box; } . Post : --headings { font-weight : 600 ; } . Button : --hover-focus-active { color : blue; } . Button : active { ...

    Manning jQuery in Action.pdf

    - **Custom jQuery Selectors**: jQuery also provides methods for creating custom selectors that can match elements based on more complex conditions. **5. Generating New HTML (Chapter 2.2)** Creating ...

    jquery.validate使用攻略

    - **Custom selectors**:可以创建自定义的选择器,以适应特定的验证需求。 - **Utilities**:提供了一些辅助函数,如 `$.validator.format()` 用于格式化错误消息。 - **Validator**:是核心对象,提供了验证的方法...

    jQuery.validate.js 中文文档.pdf(整理)

    `Custom selectors` - **描述**: 提供了一些预定义的选择器,用于过滤元素。 - **示例**: - 未填写的元素: ```javascript $(':blank', form).css('background-color', 'yellow'); ``` - 已填写的元素: ```...

    Android代码-BannerLayout

    can be customized dots , title, prompt bar position,Support for custom selectors you can customize small dots, and whether to automatically rotate to the next page and rotation time support for ...

    jQuery学习2 选择器的使用说明

    <li>Custom selectors <li>Form selectors ``` - **jQuery写法**:`$("ul.myList > li > a")` 2. **后代选择器**:选择作为指定元素后代的元素。 - **写法**:`ancestor descendant` - **示例**:选择...

    jQuery validate 中文API 附validate.js中文api手册

    7. **custom selectors**: `blank`、`filled` 和 `unchecked` 是自定义选择器,用于在验证逻辑中筛选特定状态的元素。`blank` 选择器匹配无值的元素,`filled` 选择器匹配有值的元素,`unchecked` 选择器匹配未被...

    PHP-spider.zip

    supports adding custom URI discovery logic, based on XPath, CSS selectors, or plain old PHP comes with a useful set of URI filters, such as Domain limiting supports custom URI filters, both ...

    CSS3实现创意2020数字填充gif背景动画特效源码.zip

    【标题】"CSS3实现创意2020数字填充gif背景动画特效源码"涉及到的主要知识点包括CSS3的动画(Animations)技术、伪元素(Pseudo-elements)、过渡(Transitions)、选择器(Selectors)以及自定义字体(Custom Fonts...

    YuNetsurf v3.0.0 for D6-XE10 HTML5 CSS 解析

    CSS2 and CSS3 selectors. Handle most CSS2 as well as some CSS3 properties. Selector engines readily provided for Simple DOM tree. LibXml2 tree. Flexible selection API to apply CSS to custom DOM ...

    【WordPress插件】2022年最新版完整功能demo+插件1.0.2.zip

    Divi Module Custom CSS Selectors Divi模块自定义CSS选择器" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、opencart主题、PHP项目源码、安卓项目源码、ios项目源码,...

    my-custom-styles:此仓库将托管我的自定义样式表,以作为多个应用程序的团队使用

    1. **选择器(Selectors)**:选择器用于指定CSS规则将应用于哪些HTML元素。例如,`.class-name`选择器应用于具有特定类名的元素,`#id-name`选择器应用于具有特定ID的元素,而`element`选择器则应用于HTML元素自身...

    Using.Flume.Flexible.Scalable.and.Reliable.Data.Streaming.pdf

    How can you get your data from frontend ... Interceptors, Channel Selectors, Sink Groups, and Sink Processors Chapter 7. Getting Data into Flume* Chapter 8. Planning, Deploying, and Monitoring Flume

    Responsive Web Design with HTML5 and CSS3(PACKT,2ed,2015)

    Desktop-only websites just aren’t ...Learn how to use the latest features of CSS including custom fonts, nth-child selectors (and some CSS4 selectors), CSS custom properties (variables), and CSS calc

    Android代码-ChatKit

    Fully customizable layouts - setting styles out of the box (use your own colors, text appearances, drawables, selectors and sizes) or even create your own custom markup or/and holders for unique be

    ActiveMQ中文手册

    2.4.3 Custom Authentication Implementation 14 2.4.4 Authorization Plugin 15 2.5 Clustering 16 2.5.1 Queue consumer clusters 16 2.5.2 Broker clusters 16 2.5.3 Master Slave 18 2.6 Features ...

    Interactive Applications Using Matplotlib

    Chapter 4, Widgets, covers built-in widgets such as buttons, checkboxes, selectors,lassos, and sliders, which are all explained and demonstrated. Here, you'll also learn about other useful third-party...

Global site tag (gtag.js) - Google Analytics