0

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);
}

1 Answer 1

1

Your click functions needs delegating:

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

Jquery Delegate

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.