The [attribute|=value] selector selects elements whose attribute value equal to a specified string or string followed by a hyphen.
This selector is used to handle language attributes.
$("[attribute|='value']")
Parameter | Optional | Description |
---|---|---|
attribute | Required. | the attribute to find |
value | Required. | the string the attribute value should start with |
Select all <p> elements with a title attribute that starts with the value "Flag":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p[title|='Flag']").css("background-color", "yellow");}); </script>// ww w .j a va2 s . com </head> <body> <p title="Flag">This is a paragraph.</p> <p title="flag">This is a paragraph.</p> <p title="Tom">This is a paragraph.</p> <p title="See You Flag">This is a paragraph.</p> <p title="Flag-the day after today">This is a paragraph.</p> </body> </html>