I'm trying to use Jquery to change the value from a "select" input in a form, but when it changes, the function for that change doesn't work.
HTML:
<select id='select'> <option checked value='1' >Option 1</option> <option value='2' >Option 2</option> </select> <div id='text'>Option 1 selected</div> <div id='button'>Click to select Option 2</div> JQuery:
$('#select').change(function(){ if($(this).val() == '1'){ $('#text').text('Option 1 selected'); } else if($(this).val() == '2'){ $('#text').text('Option 2 selected'); } }); $('#button').click(function(){ $('#select').val('2'); }) CSS:
#button { cursor: pointer; color: white; background: red; padding: 5px; display: inline-block; } Demo: https://jsfiddle.net/fdko9nna/
When I click the #buttondiv, it changes the select field, but the function that changes the #text it's not executed.
Thanks.