This is probably the weirdest JavaScript issue ever:
$('div.GiftContainer').live('click', function () {
var self = $(this);
var price = $(this).attr('data-price');
if (!self.hasClass('selected')) {
if (price <= MyCredits) { // always returns true
alert('OK');
self.addClass('selected').siblings().removeClass('selected');
} else {
alert('MOO!');
}
} else {
self.removeClass('selected');
}
});
Returns true even when I added console.log(price + ' ' + MyCredits); right before the condition and price was smaller than MyCredits.
What could it be…
Try parseInt(). That should fix it to make sure that they’re being properly interpreted by JS.