EventListener does not work with 2 or more inputs

1

So, my friends, I have a page with a for that does create several forms. In each form I have an input file, which I want to handle individually. However, when I try to use some eventlistener, it only works with the first input of the for. I do not know how I can make everyone work. I did a JSFiddle illustrating my problem here. Note that the alert is only triggered in the first case, nothing else happens in the others.

Does anyone have a solution?

EDIT fiddle link link

    
asked by anonymous 11.02.2016 / 17:20

1 answer

2

You need to use querySelectorAll and use each for each of the elements, as below:

var inputs = document.querySelectorAll('input.sliderAluno');

[].forEach.call(inputs, function(input) {
    input.onchange= function()
    {
        alert("event");
    }
});
    
11.02.2016 / 17:46