fix in example in jquery documentation

fix in example in jquery documentation

Good day. I've been trying to get the code in this page to work
submit example

Someone needs to remind readers that you MUST place the script under the html code because doing it otherwise wouldn't make it run properly. The alert wouldn't appear. But placing it under the html code, by the time this script is reach and executed, it'll recognize $("#target")
In other words, you need to tell people why the script was written after the html code.

In doing so, you can also prevent an alternative if you want the script to be at the top by placing the code inside document.ready.

I posted the full example.

  1. <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script>
    $(document).ready(function()
     {
        $( "#target" ).submit(function( event ) {
            alert( "Handler for .submit() called." );
            event.preventDefault();
        });
     });
    </script>

    <html>
    <body>
    <form id="target" action="destination.html">
    <input type="text" value="Hello there">
    <input type="submit" value="Go">
    </form>
    <div id="other">
    Trigger the handler
    </div>
    </body>




















I don't know if I'm "allowed" to do this but I wanted to say it nonetheless as it took me forever to get to this point and I'm just beginning :D The first guy I talked to suggested I place the script under html but didn't give me a proper reason. The other guy told me why. Both said this was the only way. I of course wasn't convinced. If this was the only way, why does the submit event/method exist? So a third guy told me to use document.ready if I wanted to use submit().