jQuery <input> handle focus event

Description

jQuery <input> handle focus event

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Executing a Function on Focus Event in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
    label{/*from   w  ww.j  a  va2s  .  c om*/
        display: block;
        margin: 5px 0;
    }
    label span{
        display: none;
    }
</style>
<script>
$(document).ready(function(){
    $("input").focus(function(){
        $(this).next("span").show().fadeOut("slow");
    });
});
</script>
</head>
<body>
    <form>
        <label>Email: <input type="text"> <span>focus fire</span></label>
        <label>Password: <input type="password"> <span>focus fire</span></label>
        <label><input type="submit" value="Sign In"> <span>focus fire</span></label>
    </form>
    <p>Click on the form control or press the "Tab" key to set focus.</p>
</body>
</html>



PreviousNext

Related