Home > Mobile >  Triggering change event
Triggering change event

Time:04-18

I've got the following function:

$('#id_service').on('change', function() {

     afunction($(this));
            
});

I've then got another function that manually changes #id_service

$(document).ready(function() {

   $('#id_primary option:nth-child(2)').attr('selected', 'selected');
       
});

This function that sets the section option to select isn't triggering 'on change' function. How would I do this?

Thanks!

CodePudding user response:

Maybe try using the jquery.trigger() function?

    $(document).ready(function() {
       $('#id_primary option:nth-child(2)').attr('selected', 'selected');
       $('#id_service').trigger('change');
    });
  • Related