Home  >  Article  >  Web Front-end  >  In jQuery: lt selector usage example_jquery

In jQuery: lt selector usage example_jquery

WBOY
WBOYOriginal
2016-05-16 16:23:381136browse

The example in this article describes the usage of the :lt selector in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This selector matches all elements less than the given index value.
The minimum index value starts from 0.

Grammar structure:

Copy code The code is as follows:
$(":lt(index)")

This selector is generally used in conjunction with other selectors, such as class selectors, element selectors, etc.
For example:

Copy code The code is as follows:
$("li:lt(3)").css("color", "blue")

The above code can set the font color in li elements with index less than 3 to blue.
If not used with other selectors, the default state is to be used with the * selector, for example, $(":lt") is equivalent to $("*:lt").

Parameter list:

参数 描述
index 给定的索引值。

Example code:

Example 1:

Copy code The code is as follows:






Script Home





  • html area

  • div css area

  • jQuery Zone

  • Javascript Zone





The above code can set the font color in the li element collection with an index value less than 3 to blue.

Example 2:

Copy code The code is as follows:






Script Home





  • html area

  • div css area

  • jQuery Zone

  • Javascript Zone







Since the above code does not specify a selector to be used with the :lt selector, it is used with the * selector by default. Therefore, the above code can select all elements in the current document that have an index value less than 11. The border color is set to red.

I hope this article will be helpful to everyone’s jquery programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn