0

I would like to set a jQuery variable, then target a className by doing something like this:

var chosen_language = '#English';

if (this.className == chosen_language) {
    blah blah blah;
}

But the above does not seem to work because I have 3 separate classes here. The HTML looks something like this below:

<a id="English" class"English nturl en" href="#">English</a>

How can I target ONLY the 3rd class (i.e. en), using the exact example that I have above?

1
  • Class Names don't start with English... See my answer bellow Commented Nov 12, 2013 at 23:09

1 Answer 1

4

With jQuery :

if ($(this).hasClass(chosen_language)) { };
Sign up to request clarification or add additional context in comments.

4 Comments

I'm trying to target only class en, how would I be able to do that?
if ($(this).hasClass('en')) { };
Yep, that worked. I'm having an off day - so easy. Thank you!
one question: I should have asked how to get the name of the 3rd class, based on the ID of #English. #English will always be changing, so I cannot use en because it needs to be variable. How can I dynamically get classname of en?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.