How to trigger an event on a select menu item with JQuery -
a basic question, i'm sure, can't seem crack. trigger simple event when specific option in select menu picked.
this basic select menu item:
<select id="myselect"> <option value=1>1 - not show</option> <option value=2>2 - not show</option> <option value=3>3 - show</option> </select>
the item targeted event:
<div id="see-me-now" style="display:none;">boo!</div>
the jquery i've got far:
$(document).ready(function(){ $("#myselect").change(function(){ $("#see-me-now").fadein('slow'); }); });
now, know i'm missing code, can't seem code is:
$(document).ready(function(){ $("#myselect").change(function(){ $(*missing code goes here, bet*){ $("#see-me-now").fadein('slow'); }); }); });
thanks
what have done right. forgot add condition. see code below:
$(document).ready(function(){ $("#myselect").change(function(){ if ($(this).val() == 3) { $("#see-me-now").fadein('slow'); } }); });
and there's error in code. if
condition should have different closing.
snippet
$(document).ready(function(){ $("#myselect").change(function(){ if ($(this).val() == 3) { $("#see-me-now").fadein('slow'); } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <select id="myselect"> <option value=1>1 - not show</option> <option value=2>2 - not show</option> <option value=3>3 - show</option> </select> <div id="see-me-now" style="display:none;">boo!</div>
Comments
Post a Comment