Home >Web Front-end >JS Tutorial >Detailed explanation of the use of jQuery selector [attribute]

Detailed explanation of the use of jQuery selector [attribute]

黄舟
黄舟Original
2017-06-23 13:09:301215browse

Overview

Matches elements containing the given attribute. Note that in jQuery 1.3, the leading @ symbol has been abolished! If you want to be compatible with the latest version, simply remove the @ symbol.

Parameters

attributeStringV1.0

Attribute name

Example

Description:

Find all div elements containing the id attribute

HTML Code:

<div> <p>Hello!</p> </div> <div id="test2"></div>

jQuery Code:

$("div[id]")

Result:

[ <div id="test2"></div> ]

This selector can match with the given attribute element.

Syntax structure:

$("[attribute]")

Parameter list:

Parameter               Description    

attribute               The name of the attribute to be found.

Example code:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title></title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){ 
  $("button").click(function(){ 
    $("[title]").css("color","blue"); 
  }); 
}); 
</script>
</head>
<body>
<ul>
  <li id="first">html专区</li>
  <li id="second" title="jquery">Jquery专区</li>
</ul>
<ul>
  <li id="third">欢迎来到脚本之家</li>
  <li>欢迎您</li>
</ul>
<button>点击查看效果</button>
</body>
</html>

The above code can set the text color in the li element with the title attribute to blue.

The above is the detailed content of Detailed explanation of the use of jQuery selector [attribute]. 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