How to find all links with an hreflang attribute using jQuery ?
In this article, we will learn to find all links with a hreflang attribute. The hreflang is an attribute that tells search engines the relationship between pages in different languages on your website.
You can use this attribute in the following three ways.
- As a link in the HTML head of the page(<head>).
- In the HTTP header (example PDFs)
- On the XML sitemap
You can find all links with an hreflang attribute on your page using the attributeContainsPrefix selector.
attributeContainsPrefix selector: This selector is used to select elements that have the specified attribute with a value either equal to a given string or starting with that string.
jQuery( "[attribute|='value']" ) $( "a[hreflang|='en']" )
Example 1: In the following examples, we first find the hreflang and then highlight it using CSS properties. The hreflang attribute with a value ‘en’ gets highlighted with the red dotted border.