home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference

Element.click() Method


Element.click() Method---simulate a mouse click on a form element


Navigator 2.0, Internet Explorer 3.0








The click() method of a form element simulates a mouse click on the form element, but does not invoke the onclick() event handler of the element.

The click() method is not often useful. Because it does not invoke the onClick() event handler, it is not useful to call this method on Button elements--they don't have any behavior other than that defined by the onClick() handler. Calling click() on a Submit or Reset element will submit or reset a form, but this can be more directly achieved with the submit() and reset() method of the Form object itself.

You can call click() on Radio and Checkbox elements to check or uncheck those buttons, but it is generally easier to simply set the checked property of those elements. Furthermore, click() does not work for these elements in Navigator 2.0 or 3.0 on Unix platforms.

On Windows (but not Unix) platforms, you can even call click() for Select elements, but doing so does not accomplish much. For Select objects implemented as drop-down menus, for example click() will cause the menu to drop down, but does not actually select an item from the menu. It is poor user-interface design to do this sort of thing--the user should always be in control of the form elements.

Finally, the click() method is not defined for the text input form elements: Text, Textarea, Password and FileUpload.

Previous Home Next
Element.checked Book Index Element.defaultChecked

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell