JQuery selector | = in $ ("[name | = 'value']")

I found this snippet in javascript code:

var name = "someString";
var s = "[name|='"+name+"']";
var nArr = $JQ(s);

Can someone explain what is doing |=?

I see in my debugging tool that I get an array of jQuery elements, all of which have someStringin their name. But I could not find an explanation in the jQuery documentation. What am I missing?

+4
source share
1 answer

This attribute contains a prefix selector.

Selects elements with the specified attribute with a value equal to the specified string, or starting with this string, followed by a hyphen (-).

$("a[hreflang|='en']").css("color", "green");
a {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<a href="example.html" hreflang="en">Some text</a>
<a href="example.html" hreflang="en-UK">Some other text</a>
<a href="example.html" hreflang="english">will not be selected</a>
Run codeHide result

CSS .

W3

att, "val", "val", "-" (U + 002D). , (, hreflang a HTML), BCP 47 ([BCP47]) .

+4

Source: https://habr.com/ru/post/1612903/


All Articles