Jason Howard
Jason Howard

Reputation: 1586

Triggering change event

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!

Upvotes: 0

Views: 41

Answers (1)

Trent
Trent

Reputation: 76

Maybe try using the jquery.trigger() function?

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

Upvotes: 2

Related Questions