[attribute|=value] selector selects elements whose attribute is equal to a string or starting with that string followed by a hyphen. - Javascript jQuery Selector

Javascript examples for jQuery Selector:attribute start with word or followed by hyphen

Description

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").

Syntax

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":

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials