First of all the fiddle: http://jsfiddle.net/6d82Q/1/
In my HTML I have:
<div class="myClass" data-status="true"></div>
<div class="myClass" data-status="false"></div>
I want to add a CSS-class to a div depending on the status:
$('.myClass').each(function()
{
// compare status
if($(this).data('status') == 'true')
{
$(this).addClass('myTrueClass');
}
else
{
$(this).addClass('myFalseClass');
}
});
The Problem is, that always myFalseClass
is added.
My question is: How can the problem be fixed and why does it occur in the first place?