HTML DOM Input URL focus() Method
The Input URL focus() method in HTML DOM is used to get focus to the Input URL field when the event occurs. We can use this method for directing the focus of the user when an event occurs.
Syntax:
URLObject.focus()
Parameters: This method does not contain any parameter values.
Return Value: It does not return any value.
Example: Below program illustrates the use of the input URL focus() method in HTML DOM.
HTML
!DOCTYPE html>
< html >
< body style = "text-align:center;" >
< h1 style = "color:green" >
GeeksforGeeks
</ h1 >
< strong >DOM Input URL focus() method</ strong >
< form id = "myForm" >
< input type = "URL" id = "url_id" name = "Lnk" >
</ form >
< br >
< button onclick = "myfocus()" >
Get Focus!
</ button >
< script >
function myfocus() {
// Use the focus() method on the
// selected element
document.getElementById("url_id").focus();
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Internet Explorer
- Opera
- Safari
Last Updated :
13 Feb, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...