Knowledge Walls
John Peter
Pune, Maharashtra, India
How to use focus() and blur() method in Javascript with Example
Focus() and blur() 
focus() - move present focus to the element.
blur() - unfocus the element.
        <script type="text/javascript">
            function do_focus(){
            function do_blur(){

            document.getElementById("userName").onfocus = function(){
                document.getElementById("presentStatus").innerHTML = "on Focus";

            document.getElementById("userName").onblur = function(){
                document.getElementById("presentStatus").innerHTML = "on Blur";
         <input id="userName" /><br /><br />

        <button onclick="javascript:do_focus();">Focus</button>
        <button onclick="javascript:do_blur();">Blur</button>

        <br /><br />
        Status: <div id="presentStatus"></div>
Demo & Output 
Best Lessons of "Good Javascript Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details