<select>
<option value="0" id="n">n</option>
<option value="1" id="m">m</option>
</select>
In JQuery, how do I say:
When id "n" is selected...do this . (not onclick) I want onSelected.
<select>
<option value="0" id="n">n</option>
<option value="1" id="m">m</option>
</select>
In JQuery, how do I say:
When id "n" is selected...do this . (not onclick) I want onSelected.
Instead of writing onclick for each option tag, I recomment use onchange event of select. Another advantage of writing this will be you don't need to care event bubbling or event capturing and you have one method declared on select tag.
No need to use id's for options inside a select tag.
$(function(){
$("#sel1").change(function(){
switch($(this).val())
{
case "0": // do your code
break;
}
});
});
<select id="sel1">
<option value="0" id="n">n</option>
<option value="1" id="m">m</option>
</select>