jQuery :lang() Selector


The :lang() selector in jQuery is used to select all elements with the specific language set as the parameter.

Syntax

The syntax is as follows −

$(":lang(language)")

Here, the parameter language can be en, en-us, en-uk, etc. These are language codes.

Example

Let us now see an example to implement the :lang() selector −

<!DOCTYPE html>
<html>
<head>
<style>
   .demo {
      background-color: blue;
      color: white;
      border: 2px yellow dashed;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("p:lang(fr)").addClass("demo");
   });
</script>
</head>
<body>
<h2>Language</h2>
<p>We are learning French</p>
<p lang="fr">Nous apprenons le français</p>
</body>
</html>

Output

This will produce the following output −

raja
Published on 05-Nov-2019 10:34:53
Advertisements