0

I have a small problem with this array.

I need to add css class in each key has a value 0 for exemple, this is my essay:

var obj = {"test_1":"1","test_2":"1","test_3":"0","test_4":"0","test_5":"0","test_6":"1","test_7":"0"};
$.each( obj, function( key, value ) { 
  alert("key " + key + " has value " + obj[key]);
  if(value = 0) {
    $('#'+ key).addClass('hidden');// hidden only the obj has value = 0
  }
});

http://jsfiddle.net/8TT4p/1636/

3
  • 3
    use == instead of = in your test condition for value Commented Dec 30, 2015 at 10:17
  • Done ! jsfiddle.net/8TT4p/1638 Thank you very much Immanuel Valle Commented Dec 30, 2015 at 10:21
  • No problem. If this one helped you, kindly check the posted answer below so others can see it. :) Commented Dec 30, 2015 at 10:22

1 Answer 1

2

You are assigning 0 to variable value , which will always return true. Replace it with if(value==0) so it will return a boolean value.

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

Comments

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.