'Jquery show div from option already "selected"

I want show div when its run without having to select first, this is my code line, I need help, thank you in advance. here's my script fiddle

I have successfully displayed div when the option option is change, what I want is when it's first run, the selected option that already selected appears immediately, I am searching but confused by this line of code: $(this).find("option:selected").each(function().

My script before inline : 8 the option value="5" is already "selected", but when I run the code, it must change the option to sho the div. (sorry for my bad english).



Solution 1:[1]

just use $('#pilih-jurusan').change(); at the end of code

Solution 2:[2]

$(object).on 

this function will let object bind a event

you shoulde trigger that event, like this:

$(object).trigger(event)

Solution 3:[3]

You need to add trigger() method for change event below of on change method like below snippet.

$(document).ready(function(){
    $('#pilih-jurusan').on('change', function() {
      //Your existing code
    });
    
     // Add trigger method for change event.
    $('#pilih-jurusan').trigger('change');
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mohammadreza Esmaeeli
Solution 2 databorker
Solution 3 Raeesh Alam