JQuery how to monitor stock exchange?

3

I have a radio button:

<input type="radio" value="1" id="monitor" style="display:none;">

Here I change the value of it, and would like an alarm to be triggered:

$(function(){

        $("#umItemQualquer").click(function(){

            alert("antes da mudança " + $("#monitor").val())

            $("#monitor").val(2); //Alterando valor do radio

            alert("depois da mudança " + $("#monitor").val())

        });

        // Essa função não deveria ser ativada?
        $("#monitor").change(function(){
            alert("agora o bicho vai pegar!")
            dispararAlarme();
        });

    });
    
asked by anonymous 08.06.2015 / 04:06

1 answer

3

The change event is only called when the field loses focus and has its value modified. More information here .

When you change the value by command, it has the value modified, but does not have the loss of focus, so change is not called.

If you want to force the activation manually, just put

$("#monitor").trigger("change");
    
08.06.2015 / 04:20