javascript - Simple jQuery blur function not working -
i'm having 1 of moments can't simple piece of code work. despite spending on hour on this, can't piece of code work;
<!doctype html> <html lang="en"> <head> <title><?php echo 'test'; ?></title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"><!-- jquery stylesheet --> <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script><!-- jquery libary --> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script><!-- jquery ui --> </head> <body> <script> $("#target").blur(function () { alert("handler .blur() called."); }); </script> <form> <input id="target" type="text" value="field 1"> <input type="text" value="field 2"> </form> </body> </html>
i've run code through html 5 validator ensure wasn't stupid , i've ensured i'm using latest version of jquery. strange thing is, can make code work on jsfiddle.
$(function(){ $("#target").blur(function () { alert("handler .blur() called."); }); });
you need update script written above. add wrapper.
you binding event using jquery. however, not necessary when script executes, jquery has been loaded then, hence, binding not happen, hence, function not triggered.
you need add wrapper of on ready of jquery, make sures binding of events , script execution done once dom ready.
here, have created plunker working version - http://plnkr.co/edit/xhur8f1ur194ii6xlrby?p=preview
Comments
Post a Comment