jqueryhtmlfocusout

focusout not working jquery


I am having some issues with focusout. I want an alert when an input box is selected and I click out of the inputbox. However, after I click it and click out of it, I do not get an alert. Here is my code:

<script>
    $(document).ready(function(){

        $("#val1").focusout(function(){
            alert('focusout');
        });
    });
</script>


<p><label>Value: </label><input id="val1" type="text" placeholder="example: val"></p>

Any ideas? Thanks!


Solution

  • It works after copied your code into FIDDLE. I also added focusin function as well. So you can do some comparison. focusout with focusin

        $("#val1").focusout(function(){
            alert('focusout');
        });
        $("#val1").focusin(function(){
            alert('focusin');
        });