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

jQuery: gt selector usage example_jquery

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

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

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

Grammar structure:

Copy code The code is as follows:
$(":gt(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:gt(0)").css("color", "blue")

The above code can set the font color in the li element with an index greater than 0 to green.
If not used with other selectors, the default state is to be used with the * selector, for example, $(":gt") is equivalent to $("*:gt").

Parameter list:

参数 描述
index 给定的索引值

Example code:

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 whose index value is greater than 0 in the li element collection 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 :gt 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 greater than 1. Font color is set to blue.

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

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