PJoy PJoy - 4 months ago 7
jQuery Question

Can't handle jQuery form event

I'm trying to handle when an input field is out of focus but I can't get the following to work :

jQuery("input").focusout(function() {
alert('yo');
});


Notes :


  1. It doesn't work for any of the form events (
    blur()
    ,
    change()
    ,
    focus()
    , etc.)

  2. It works when I replace
    "input"
    by
    document
    but it's not what I want to do.

  3. I'm using Wordpress so I'm adding the javascript code the normal way like so :

    function add_scripts() {
    wp_register_script('MyScript', 'script.js', array('jquery'), true);
    wp_enqueue_script('MyScript');
    }


Answer

Ok, I found the solution, it appeared that I didn't include my function inside ready function $(function(){}); which seems to be mandatory in jQuery if we want to reach all the elements in the page.

Comments