jQuery check if attr = value

beefchimi picture beefchimi · Jun 26, 2012 · Viewed 131.8k times · Source

I seem to be having trouble with my code. I need to say:

if ( $('html').attr('lang').val() == 'fr-FR' ) {
    // do this
} else {
    // do that
}

When I check the console, I just get an error telling me this isn't a function. Help would be appreciated.

Thanks,

Answer

Miguel Ribeiro picture Miguel Ribeiro · Jun 26, 2012

Just remove the .val(). Like:

if ( $('html').attr('lang') == 'fr-FR' ) {
    // do this
} else {
    // do that
}