jQuery Multiple Event Handling Problems
HTML
<input type="text" id="textField" />
<input type="button" onclick="setFocus();" value="click here" />
<ol>
<li>Type some text into the textfield.</li>
<li>Click the button.</li>
<li>Click out of the textfield, or
<br /> <i>press enter for some weird behavior.</i>
</li>
</ol>
JavaScript
function setFocus() {
$("#textField").focus();
$("#textField").select();
var count = 1;
$("#textField").one("focusout keydown", function (e) {
if (e.type == "focusout" || e.keyCode == 13) {
alert(count++);
}
// this doesn't seem to be working correctly:
$("#textField").off("focusout keydown");
});
}