jQuery Tutorial Tutorials - jQuery :lang() selector

:lang() selector

The :lang() selector selects all elements(and any of their descendant) of the specified language. It matches elements that takes a whole word a value or immediately followed by a hyphen(-).

For example, the selector $("div:lang(en)") will match <div lang="en"> and <div lang="en-us"> (and any of their descendant <div>s), but not <div lang="fr">

jQuery :lang() selector Syntax
$(':lang(language)')
jQuery :lang() selector Examples

In below example,we will set a different background color according to the language of the element.

Please note that the elements [<h2>France</h2>,<p>la france</p>] inherit language from their parent element. So the selector $(':lang(fr)') will match these two elements.

<h2 lang="en-us">USA</h2>
<p lang="en">contents</p>
<div lang="fr">
    <h2>France</h2>
    <p>la france</p>
</div>
<script>
    $("h2:lang(en)").css("background",'aqua');
    $("p:lang(en)").css("background",'coral');
    $("h2:lang(fr)").css("background",'brown');
    $("p:lang(fr)").css("background",'orange');
</script>

Try now

Date:2019-08-18 02:00:22 From:www.Lautturi.com author:Lautturi