Attribute Selectors


SelectorExampleDescription
[attribute]$("[href]")Selects all elements with a href attribute, with any value.
[attribute="value"]$('a[target="_blank"]')Selects all <a> elements that have the target attribute with a value equal to "_blank".
[attribute="value"]$('a[target!="_blank"]')Selects all <a> elements that don’t have the target attribute, or if have don’t with a value "_blank".
[attribute$="value"]$('img[src$=".png"]')Selects all <img> elements that have the src attribute with a value ending with ".png".
[attribute|="value"]$('a[hreflang|="en"]')Selects all <a> elements that have the hreflang attribute with a value equal to "en", or starting with "en" followed by a hyphen, like "en-US".
[attribute^="value"]$('img[title^="Smiley"]')Selects all <img> elements that have the title attribute with a value beginning exactly with a “Smiley” string.
[attribute~="value"]$('img[title~="Kites"]')Selects all <img> elements that have the title attribute with a value containing the word “Kites”, delimited by spaces.
[attribute*="value"]$('input[name*="male"]')Selects all <input> elements that have the name attribute with a value containing the substring “male”.

Leave a Reply

Your email address will not be published. Required fields are marked *