Reputation: 3
I want to make a button to increment de value of differents inputs. Then I thought the best way would be to create a class and eliminating it . Once I create the class I can not access it . If I click the button does nothing.
var valorDipVl = Number($('#dip-vl').val());
var valorForiaVl = Number($('#foriaVl').val());
$('#dip-vl').on('focus',function() {
$('#arriba>button').removeClass().addClass('activo');
})
$('#foriaVl').on('focus',function() {
$('#arriba>button').removeClass().addClass('activo2');
})
$('button.activo').on('click', function() {
valorDipVl += 1;
$('#dip-vl').attr('value', valorDipVl);
})
$('button.activo2').on('click', function() {
valorForiaVl+=1;
$('#foriaVl').attr('value', valorForiaVl);
}
Upvotes: 0
Views: 41
Reputation: 8246
Your click functions needs delegating:
$(document).on('click', 'button.activo', function() {
// Code
});
Upvotes: 1