JavaScript element.focus() Method
You are Here:
JavaScript element.focus() Method
The element.focus()
method requests to bring the focus to the specified element, if it can be focused.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p>Name</p>
<input type="text" value="John">
<p>Age</p>
<input type="text" value="45">
<p>Click on the button to focus and to blur.</p>
<button onclick="myFocus()">Focus</button>
<button onclick="myBlur()">Blur</button>
<p id="point"></p>
<script>
var x = document.getElementById("point");
var elem = document.getElementsByTagName("input")[0];
function myFocus(){
elem.focus();
}
function myBlur(){
elem.blur();
}
</script>
</body>
</html>
Syntax
element.focus()
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.