
- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
jQuery :lang() Selector
The :lang() selector is used to select elements based on their language attribute. It specifically targets the lang attribute of HTML elements, which specifies the language of the element's content.
Syntax
Following is the syntax of :lang selector in jQuery −
$(":lang(language)")
Parameters
Here is the description of the above syntax −
- The :lang specifies the language to match.
- It can be a language code like "en" for English, "fr" for French, etc. This value can also be more specific, such as "en-US" for American English.
- The value inside the :lang() selector is case-insensitive.
Example 1
In the following example, we are using the :lang() selector to select the paragraphs with the lang="en" attribute −
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(":lang(en)").css("background-color", "yellow"); }); </script> </head> <body> <p lang="en">This paragraph is in English.</p> <p lang="fr">Ce paragraphe est en français.</p> <p lang="en-US">This paragraph is in American English.</p> </body> </html>
After executing the above program, It selects the paragraphs with the lang="en" attribute and highlights them with yellow background color.
Example 2
In this example, we are selecting all the paragraphs with the lang="fr" attribute −
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(":lang(fr)").css("background-color", "yellow"); }); </script> </head> <body> <p lang="en">This paragraph is in English.</p> <p lang="fr">Ce paragraphe est en français.</p> <p lang="en-US">This paragraph is in American English.</p> </body> </html>
After executing, the :lang selects the paragraphs with the lang="fr" attribute and highlights them with yellow background color.
Example 3
This example selects the paragraphs with the lang="en" or lang="es" attributes −
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(":lang(en), :lang(es)").css("background-color", "yellow"); }); </script> </head> <body> <p lang="en">This paragraph is in English.</p> <p lang="fr">Ce paragraphe est en français.</p> <p lang="es">Este párrafo está en español.</p> <p lang="de">Dieser Absatz ist auf Deutsch.</p> </body> </html>
After executing, the :lang selects the paragraphs with the lang="en" or lang="es" attributes and highlights them with yellow background color.