Attribute filter selector in jquery

巴扎黑
Release: 2017-06-21 10:16:28
Original
1718 people have browsed it

This article mainly introduces theattributesfilter selector ofjqueryselector. Friends who need it can come and refer to it. I hope it will be helpful to everyone

The code is as follows:

Copy after login

The code is as follows:

 

Hello

ID为test的p

足球 排球 篮球 其他
Copy after login


1. [attribute] Usage
Definition: Match elements containing the given attribute

The code is as follows:

$("p[id]").addClass("highlight"); //查找所有含有ID属性的p元素
Copy after login


2. [attribute=value] Usage
Definition: Match the given attribute to a specific The value element

code is as follows:

$("input[name='basketball']").attr("checked",true); //name属性值为basketball的input元素选中
Copy after login

3. [attribute!=value] Usage
Definition: Match the given attribute that does not contain The code for an element with a specific value

is as follows:

$("input[name!='basketball']").attr("checked",true); //name属性值不为basketball的input元素选中 //此选择器等价于:not([attr=value])要匹配含有特定属性但不等于特定值的元素,请使用[attr]:not([attr=value]) $("input:not(input[name='basketball'])").attr("checked",true);
Copy after login


4. [attribute^=value] Usage
Definition: Match to A certain attribute is an element starting with a certain value

The code is as follows:

$("input[name^='foot']").attr("checked",true); //查找所有 name 以 'foot' 开始的 input 元素
Copy after login

5. [attribute$=value] Usage
Definition: Matches elements where the given attribute ends with some value

The code is as follows:

$("input[name$='ball']").attr("checked",true); //查找所有 name 以 'ball' 结尾的 input 元素
Copy after login

6. [attribute*=value] Usage
Definition: Match the given attribute to elements containing certain values

The code is as follows:

$("input[name*='sket']").attr("checked",true); //查找所有 name 包含 'sket' 的 input 元素
Copy after login

7. [selector1][selector2][selectorN]Usage
Definition: Compositeattribute selector, used when multiple conditions need to be met at the same time

The code is as follows:

$("input[id][name$='ball']").attr("checked",true); //找到所有含有 id属性,并且它的 name属性是以 ball结尾的
Copy after login

The above is the detailed content of Attribute filter selector in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!