Home > Net >  Jquery show div from option already "selected"
Jquery show div from option already "selected"

Time:04-06

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).

CodePudding user response:

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

CodePudding user response:

$(object).on 

this function will let object bind a event

you shoulde trigger that event, like this:

$(object).trigger(event)

CodePudding user response:

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');
});
  • Related