Trung Tran
Trung Tran

Reputation: 13721

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!

Upvotes: 3

Views: 8494

Answers (2)

user2452922
user2452922

Reputation: 173

.focusout() only works when you click on another focusable element. The problem, which I'm trying to sort through as well, is what happens when you click right outside of the input box. The input no longer has focus, but the focusout event is not triggered.

I would appreciate anyone's thoughts on this!!

Upvotes: 6

Lumi Lu
Lumi Lu

Reputation: 3305

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');
    });

Upvotes: 1

Related Questions