javascript - Jquery onfocus not working -
i have text area , i'm trying run function based on when spacebar hit. however, code not working , can't seem figure out why. looks right research i've done.
here's text area definition:
<div class="divwithscroll" id="my_text" contenteditable="true" onkeypress="return mykeypress(event)" onkeydown="return onkeydown(event)">
here jquery code have on page far trying run .onfocus()
$('document').ready(function () { $('#my_text').focus(function () { $('#my_text').keydown(function (e) { if (e.keycode == '32') { alert('space'); } }); alert("focused!"); }); });
it because you're using alert. stop using alert troubleshooting
this works -
$('#my_text').focus(function () { $('#my_text').keyup(function (e) { if (e.keycode == '32') { console.log('space'); } }); console.log("focused!"); });
it improve utilize keyup()
in circumstance too, avoid issues on when key pressed. example
javascript jquery
No comments:
Post a Comment