jQuery Attribute Selectors allow you to select HTML elements based on the presence or value of their attributes. They are extremely useful when elements do not have unique IDs or classes but share common attributes.
$("[attr]") → selects elements with the attribute$("[attr='value']") → exact match$("[attr!='value']") → not equal$("[attr^='value']") → starts with$("[attr$='value']") → ends with$("[attr*='value']") → contains
// Select elements that have a title attribute
$("[title]").css("border","2px solid red");
// Select input elements with type="text"
$("input[type='text']").css("background","lightyellow");
// Select links that start with https
$("a[href^='https']").css("color","green");
When these selectors run, only the elements matching the attribute condition are affected. This helps target very specific elements without adding extra classes or IDs.
Below is a simple interactive idea: clicking the button highlights all elements that contain a specific attribute.
// Highlight all elements with data-role attribute on button click
$("#btn").click(function(){
$("[data-role]").css("background","#dbeafe");
});
data-* attributes for custom logicalt attributeuser.pdf