Javascript examples for jQuery Selector:attribute start with word or followed by hyphen
The [attribute|=value] selector selects elements whose attribute is equal to a string or starting with that string followed by a hyphen.
This selector is often used to handle language attributes (like "en-us").
Parameter | Description |
---|---|
attribute | Required. attribute to find |
value | Required. string to start with |
The following code shows how to select all <p> elements with a title attribute that starts with the value "en":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("a[hreflang|='en']").css("background-color", "yellow");}); </script>//w w w . j a v a 2 s .com </head> <body> <a href="http://www.java2s.com" hreflang="en">java2s.com</a><br> <a href="http://www.java2s.com" hreflang="en-us">java2s.com</a><br> <a href="http://www.java2s.com" hreflang="en-ca">java2s.com</a><br> <a href="http://www.java2s.com" hreflang="us-en">java2s.com</a><br> <a href="http://www.java2s.com" hreflang="fr">java2s.com</a> </body> </html>