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

Detailed explanation of the use of jQuery selector [attribute]

黄舟
Release: 2017-06-23 13:09:30
Original
1248 people have browsed it

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
Copy after login

Attribute name

Example

Description:

Find all div elements containing the id attribute

HTML Code:

<div> <p>Hello!</p> </div> <div id="test2"></div>
Copy after login

jQuery Code:

$("div[id]")
Copy after login

Result:

[ <div id="test2"></div> ]
Copy after login

This selector can match with the given attribute element.

Syntax structure:

$("[attribute]")
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template