:langS2C Home « Selectors « :lang

Structural pseudo-class selector.

Shorthand version  $(':lang(language)')

Description

The :lang selector, selects all elements that match the specified language code.

  • This selector will check for the HTML lang common attribute within the specified elements.

If this selector is not preceded by another selector the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the example below to narrow the search and improve performance.

Syntax


Signature Description
jQuery(':lang')Language pseudo-class selector match

Parameters


Parameter Description
languageA language code that may be hyphenated to further define it:
en - English
en-us - US English

Return

N/A.

:lang Examplego to top of page Top

Selects all elements that match the specified language code.

When the button below is pressed the first time, the background colours of the paragraphs below will change, dependant upon the HTML lang common attribute that has been set.

A paragraph with a lang attribute and en subcode.

A paragraph with a lang attribute and nl subcode.

A paragraph with a lang attribute and en-us subcode.

A paragraph with no lang attribute.

A paragraph with a lang attribute and fr subcode.

A paragraph with a lang attribute and en-gb subcode.


$(function(){
  $('#btn38').one('click', function() {
    $("p:lang(en)").css('backgroundColor', 'yellow'); 
    $("p:lang(en-us)").css('backgroundColor', 'orange'); 
    $("p:lang(nl)").css('backgroundColor', 'lime'); 
    $("p:lang(fr)").css('backgroundColor', 'cyan'); 
  });
}); 

Press the button below to action the above code:


go to home page Homepage go to top of page Top