Question: I want to check if the input is empty or not **while the user is typing**

this is my code 

```
$('#visitID').on('change', function () {
        if ($('#visitID').val().length == 0) {
            $("#saveandclosebutton").hide();
        } else {
            $("#saveandclosebutton").show();
        }
    });

```

but the `saveandclosebutton` never becomes hidden even though if my input is empty.

Answer: 
Bind the event handler to both the `keyup` and `change` events, but you also want to cause the event handler to get executed when the page loads:

```
$('#visitID').on('keyup change', function() {
    $('#saveandclosebutton').toggle($(this).val().length > 0);
}).change();

```

[jsfiddle](http://jsfiddle.net/29DSq/)
Try to use **[.is()](http://api.jquery.com/is/)** with **[:empty](http://api.jquery.com/empty-selector/)** selector as well as using **[keyup](http://api.jquery.com/keyup/)** event to have live update when you're typing text inside your input:

```
$('#visitID').on('change keyup', function () {
    if ($(this).is(':empty')) {
        $("#saveandclosebutton").hide();
    } else {
        $("#saveandclosebutton").show();
    }
});

```