0

My HTML tag is this <html lang="en-US">, When I change language from English to Danish lang tag changed to this <html lang="da-DK">.

Problem: I want to add a class class="xyz" when my selected language is <html lang="da-DK">. Any possible solution to add a class using javascript.

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225

4 Answers4

0

simply use Jquery :lang() Selector

for example

if($( "html:lang(en-US)" )){ $("body").addClass( "usa" ) }

Not tested but hopefully work, see Here for more.

Ismail Farooq
  • 6,309
  • 1
  • 27
  • 47
0

You can use

  1. CSS :lang selector.More about css lang selector
  2. $( ":lang(your language)").addClass/removeClass('className');
brk
  • 48,835
  • 10
  • 56
  • 78
0

Like this:

if(document.documentElement.getAttribute('lang')=='da-DK'){
   document.body.className = ' xyz';
}
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
0

Try this it will work :

if ($('html').attr('lang') == 'da-DK') {
     $('html').addClass("xyz");
}
Debug Diva
  • 26,058
  • 13
  • 70
  • 123