Home >Web Front-end >JS Tutorial >jQuery selector: detailed explanation of header usage

jQuery selector: detailed explanation of header usage

黄舟
黄舟Original
2017-06-23 10:47:291796browse

Overview

Match title elements such as h1, h2, h3

Example

Description:

Add to all titles in the page Background color

HTML code:

<h1>Header 1</h1> <p>Contents 1</p> <h2>Header 2</h2> <p>Contents 2</p>

jQuery Code:

$(":header").css("background", "#EEE");

Result:

[ <h1 style="background:#EEE;">Header 1</h1>, <h2 style="background:#EEE;">Header 2</h2> ]

This The selector can match heading elements, i.e. (h1-h6).

Grammar structure:

$(":header")

This selector is generally used in conjunction with other selectors, such as Class selector and Element selector, etc. wait. For example:

$(".qiantai:header").css("color","blue")

The above code can set the font color in the title element with the class name qiantai to blue.

If not used with other selectors, the default state is to be used with the * selector. For example, $(":header") is equivalent to $("*: header").

Example code:

Example 1:






脚本之家 
 
 
 
 

    前台专区版块

  • html专区
  • div+css专区
  • jQuery专区
  • Javascript专区

    后台专区版块

  • ASP专区
  • php专区

##The above code can be used to title the class attribute value of qiantai The text color in the element is set to blue.

Example 2:






脚本之家 
 
 
 
 

    前台专区版块

  • html专区
  • div+css专区
  • jQuery专区
  • Javascript专区

    后台专区版块

  • ASP专区
  • php专区


Since the above code does not specify a selector to be used with the :header selector, it defaults to the * selector Used together, the above code can set the text color of the title element in all elements in the current document to blue.

The above is the detailed content of jQuery selector: detailed explanation of header usage. For more information, please follow other related articles on the PHP Chinese website!

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