Luis Cornejo
Luis Cornejo

Reputation: 3

Increment value of input through classes

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

Answers (1)

Jamie Barker
Jamie Barker

Reputation: 8246

Your click functions needs delegating:

$(document).on('click', 'button.activo', function() {
   // Code
});

Jquery Delegate

Upvotes: 1

Related Questions