1

I am trying select some divs where the data attribute x10 equals the variable Xmodule. I have something wrong with the selector but I don't know what is wrong.

 //find data element that matched Xmodule and display either on or off class
 $('div[data-x10=Xmodule]').each(function(){
 if (XStatus ==="2")
    {element.removeClass('off').addClass('on');}
 else
    {element.removeClass('on').addClass('off');};
  }); 
3
  • 1
    Where are you getting element from ? Commented Nov 19, 2013 at 18:19
  • What ever you have should work jsfiddle.net/2wr75. Can you show your html? Commented Nov 19, 2013 at 18:19
  • It works fine here: jsfiddle.net/spF8z. Is the problem that you should be using $(this) instead of element? Commented Nov 19, 2013 at 18:19

1 Answer 1

1

Try this:

It should be $('div[data-x10="Xmodule]"').

Value of attribute should be passed in quotes.

Sign up to request clarification or add additional context in comments.

1 Comment

If the value is a single word, the quotes aren't necessary. Also, even if they were, the second " would need to be inside the ].

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.