JavaScript focus() Method Tutorial

In this section, we will learn what the Element focus() method is and how to use it in JavaScript.

What is Element focus() Method in JavaScript?

The JavaScript Element focus() method is used to set the focus on an element (if that element could take focus) using JavaScript.

Element focus() Method Syntax:

element.focus();

Element focus() Method Parameter

The method does not take an argument.

Element focus() Method Return Value

The method does not return a value.

Example: using focus() method in JavaScript

See the Pen using focus() method in JavaScript by Omid Dehghan (@odchan1) on CodePen.

Leave a Reply