Button.focus()

JavaScript 1.1+, JScript 1.0+ Nav3+, IE 3+ Syntax

document.form.button.focus()

Description

The focus() method applies focus to the button without invoking the button's onFocus event handler.

Warning

In the UNIX versions of Navigator 2 and Navigator 3, the focus() method does not work for buttons.

Example

In Listing 7.24, two buttons are created to demonstrate focus. Choosing the second button causes the focus to shift to the first button instead of the focus staying on the second button, thanks to the focus() method.

Listing 7.24 Shifting the Focus to a Button Using the focus() Method
 <html> <h2>The Button Focus Game</h2> Click both buttons. Notice that when the second button is clicked focus is shifted to the first ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.