This tutorial explains usage of the has attribute selector in JQuery. The has attribute selector selects all the elements that has specified attribute and value. It represents the value mentioned in the attribute. For instance, id=”myval”, here id is an attribute and option is a value. The has attribute selector defines all the elements which contains id attribute with value “myval”.
JQuery Has Attribute Selector Syntax
It has parameters called attribute is a required parameter which specifies the attribute to find.
JQuery Has Attribute Selector Example
- $(“div[id]”).css(“border”,”2px solid orchid”); line selects all the elements with attribute id with orchid color border.
- When we run the above script, the has attribute selector selects all the elements that have specified attribute. We have used id as attribute with different values. It selects all the elements which are related to id attribute only those elements will get display with orchid color border.
JQuery Has Attribute Selector Demo
When you run the above example, you would get the following output: