I have a .change() function set for a dropdown menu with an ID of #country. When the page loads, I'm trying to set the dropdown menu to "United States" and run the .change() function:
$('#country').change(function () {
resetDisclosure();
var countryCode = $(this).val();
var countryName = $('#country option:selected').text();
$('#'+countryCode.toString()).fadeIn('slow');
if(countryCode == 'OC' || countryCode == 'EU') {
$('#OC h4, #EU h4').html('For Residents of <strong>' + countryName + '</strong>');
}
$.fancybox.resize();
$.fancybox.center();
});
$("#country").val('OC');
$("#country").change();
The last function there is wrong, because I can't force the .change() on load. How can I go about forcing the change function?
I'm super beginner and have tried to assign the contents of the .change() function to a different function and call that, but it didn't work either.
Try:
$("#country").val('OC').trigger('change');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With