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

In jQuery: only-child selector usage example_jquery

WBOY
WBOYOriginal
2016-05-16 16:22:321140browse

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

This selector will match the only child element of the parent element. If its parent element contains other elements, it will not be matched.

Grammar structure:

Copy code The code is as follows:
$(":only-child")

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:only-child").css("color"," blue")

The above code can set the font color in the li element under the ul element with only one li element to blue.

Note: It is necessary to explain the concept in combination with the above code. The parent element mentioned here is not li, but the parent element of li. Many people often mistakenly think that it matches the last element among the child elements of the li element.

Example code:

Copy code The code is as follows:






Script Home






  • ASP Tutorial



  • html tutorial

  • DIV CSS tutorial

  • jQUERY Tutorial

  • jAVAScript Tutorial






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