jquery - throw an alert if a key is pressed inside a textbox -


i trying this, not working. there way of doing differently?

if($("#user_password").keypress()){     alert("hello"); } 

user_password id of textbox on login screen.

i have canceled event textboxes when push enter, want allow them press enter in password field on login page. complete code is:

$(document).keypress(function (e) { if($("#user_password").keypress()){     alert("hello"); } if(e.which == 13 && e.target.nodename != "textarea") return false; }); 

you need set event handler, if statements aren't relevant here:

$("#user_password").keypress(function () {   alert("hello"); }); 

if want find out element triggered event, @ event's target property:

$(document).keypress(function (e) {   if (e.target == $("#user_password")[0])     alert("hello");     if(e.which == 13 && e.target.nodename != "textarea") return false; }); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -