I cannot get the following HTML to trigger my JS function:
HTML:
<table style="margin-bottom: 8px">
<tr>
<td>
<label><b>Select Language:</b></label>
</td>
<td>
<select class="dropdown" id="selectlanguage">
<option id="enBtn">English</option>
<option id="zhBtn">简体中文</option>
</select>
</td>
</tr>
</table>
JavaScript:
$("#enBtn").bind("click", function () {
setLanguage("en");
console.log("en");
});
$("#zhBtn").bind("click", function () {
setLanguage("zh");
console.log("zh");
})
The setlanguage function works fine when I use the following HTML:
<div>
<a href="#" id="enBtn">English</a>
<a href="#" id="zhBtn">简体中文</a>
</div>
But it does not work when I try to trigger with the dropdown list.
enBtn2andzhBtn2, right? And also you havesetLanguagemethod in somewhere. Can you share those?bindis deprecated in the latest version of jquery, useoninstead and when binding to a dropdown, usechangeinstead ofclick(I don't think you can register click events on the options)