Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to retrieve attribute of an HTML tag using jQuery ?
Next article icon

How to find all links with an hreflang attribute using jQuery ?

Last Updated : 06 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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. To find all links with an hreflang attribute using jQuery, you can use the attribute selector $('[hreflang]'). This will select all elements that have the hreflang attribute defined. To specifically select only <a> elements with the hreflang attribute, you can use the tag selector in combination with the attribute selector: $('a[hreflang]').

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.

Syntax:

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.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <meta charset="utf-8">     <style>         a {             display: inline-block;         }     </style>     <script src= "https://code.jquery.com/jquery-3.5.0.js">     </script> </head>  <body>     <h2 style="color:green">GeeksforGeeks</h2>     <a href="example.html" hreflang="en">GFG</a>     <a href="example.html" hreflang="en-UK">         Computer Science     </a>     <a href="example.html" hreflang="english">         will not be outlined     </a>      <script>         $("a[hreflang|='en']")             .css("border", "3px dotted red");     </script>  </body> </html> 

Output:

href lang = en

Example 2: 

HTML
<!DOCTYPE html> <html lang="en"> <head>     <meta charset="utf-8">     <style>         a {             display: inline-block;         }     </style>     <script src= "https://code.jquery.com/jquery-3.5.0.js"></script> </head>  <body>     <h2 style="color:green">GeeksforGeeks</h2>     <a href="example.html" hreflang="en">Database</a>     <a href="example.html" hreflang="en-UK">         Computer Networks     </a>     <a href="example.html" hreflang="english">         will not be outlined     </a>      <script>         $("a[hreflang|='en']")             .css("border", "3px solid green");     </script>  </body> </html> 

Output:

hreflag=en image2

Next Article
How to retrieve attribute of an HTML tag using jQuery ?

P

pall58183
Improve
Article Tags :
  • Web Technologies
  • JQuery
  • Web technologies
  • HTML-Tags
  • CSS-Properties
  • jQuery-Selectors
  • jQuery-Questions
  • jQuery

Similar Reads

  • How to change href attribute of a hyperlink using jQuery ?
    Changing the href attribute of a hyperlink using jQuery refers to the process of modifying the URL a link directs to without altering the HTML manually. This capability is useful for creating dynamic web applications where link destinations need to change based on user interactions or other conditio
    2 min read
  • How to remove all attributes of an HTML element using jQuery ?
    In this article, we will see how to remove all attributes of an HTML element using jQuery. To remove all attributes of elements, we use the removeAttributeNode() method and .removeAllAttributes(). Syntax: $.fn.removeAllAttributes = function() { return this.each(function() { $.each(this.attributes, f
    1 min read
  • How to find element with specific ID using jQuery ?
    The question is to determine whether an element with a specific id exists or not using JQuery. jQuery on() Method: This method adds one or more event handlers for the selected elements and child elements.Syntax: $(selector).on(event, childSelector, data, function, map)Parameters: event: It is requir
    3 min read
  • How to retrieve attribute of an HTML tag using jQuery ?
    In this article, we will learn how do you retrieve attributes of an HTML tag using jQuery. We can use JQuery to make this done in a few lines of code. Here we are going to build an image zooming system where will see how can an attribute of the HTML tag can be retrieved and changed. Using the attr()
    2 min read
  • How to find all children with a specified class using jQuery ?
    There are lots of javascript libraries like - anime.js, screenfull.js, moment.js, etc. JQuery is also a part of javascript libraries. It is used to simplify the code. It is a lightweight and feature-rich library. In this article, we will learn how to find all children with a specified class of each
    2 min read
  • How to find inputs with an attribute name starting with specific letter or text using jQuery?
    In this article, we will learn to find input with an attribute name starting with a specific letter or text. This task is implemented using attributeStartWith selector. attributeStartWith selector: This selector selects elements that have the specified attribute with a value beginning exactly with a
    1 min read
  • How to get an attribute value from a href link in Selenium java?
    When working with Selenium WebDriver in Java, automating web interactions often involves handling hyperlinks. A common task is to extract the attribute value from a <a> tag, specifically the href attribute, which contains the link's destination URL. Extracting this href value allows you to ver
    3 min read
  • How to find all textareas and makes a border using jQuery ?
    In this article, we will find all textareas and makes a border using jQuery. To add a border to the textarea element, we use css() method. The css() method is used to change style property of the selected element. The css() in jQuery can be used in different ways. The css() method can used to check
    1 min read
  • How to find all input elements that are enabled using jQuery?
    The jQuery " :enabled" pseudo-class selector helps to find all the input element that are enabled. This pseudo-class selector should only be used for selecting HTML elements that support the disabled attribute i.e (<button>, <input>, <textarea>, <select>, <option>, <
    2 min read
  • How to find all checkbox inputs using jQuery ?
    The task is to find all the checkbox input using jQuery. Checkboxes are the square boxes that are ticked when activated, and it is used to select one or more number of choices. Method and Selectors used: :checkbox: This selector is used to select the input element with type = checkbox. .wrap(): This
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences