skip to Main Content

with on click event i returned the below drop down element as ajax json response, without page refresh:

<select class='custom-select col-md-4' id='family'>
  <option value''> Select family</option>
  <option value='1'>familyName</option>
</select>

then I want to execute a function when changed the option using:

$('#family').on('change', function(){
        alert("Yeey");
 });

but doesn’t seem to be working.

2

Answers


  1. Your code seems to be working.
    Just add one more option in select

    For now, you have only one option which is by default selected so no change event applied.
    your script is good.
    example:

    <select class='custom-select col-md-4' id='family'>
     <option value=''>select family</option>
      <option value='1'>familyName</option>
    </select>
    
    Login or Signup to reply.
  2. Needs more than 1 option.
    By default, the first option is selected.
    So there’s no on change event triggering.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search