How do I trigger ('change') in an input select?

2

I'd like to simulate a change event in my input, but I'm not getting it to work.

As the page loads, I select a different value in my input like this:

$("#selExercicio option:contains('" + ano + "')").prop("selected", true);

It's working.

Next I try to trigger:

$("#selExercicio").trigger("change");

My input change event is this:

$("#selExercicio").change(function () {
    debugger;
    alert('Mudou');
});

And it's not calling the alert when loading the page, only when I change the input value by clicking with the mouse.

Does anyone have a clue why it's not working?

Fiddle

    
asked by anonymous 29.04.2014 / 17:23

1 answer

1

The error was that:

$("#selExercicio").trigger("change");

was being called before:

$("#selExercicio").change(function () {
    debugger;
    alert('Mudou');
});

I turned it on and it worked.

    
29.04.2014 / 19:05