dimanche 22 février 2015

NaN being returned on parseInt()


http://ift.tt/17owcEW


In the example above I have 3 buttons, orange, green and red.


On hover each reveals a [ - ] and a [ + ] button with a class of btn_action.


On click I'm trying to grab the numerical value from the target color button and then increment or decrement it by 1.


Currently I'm getting NaN on my parseInt function:



$('.btn_action').unbind('click').bind('click', function() {
var type = $(this).data('type').toString();

console.log(color);
console.log(type);

// this is returning NaN, it should be returning 1:
var number = parseInt($('option_'+color).text(), 10);
console.log(number);

if (type === 'plus') {
// number = number + 1;
$('option_'+color).text(number + 1);
console.log(number);
}
});


enter image description here


Thoughts on where I'm going wrong?





Aucun commentaire:

Enregistrer un commentaire