- jQuery Examples
- Examples - Home
- Examples - Set up
- Examples - Selectors
- Examples - Attributes
- Examples - Traversing
- Examples - CSS
- Examples - DOM
- Examples - Events
- jQuery Useful Resources
- jQuery - Quick Guide
- jQuery - Useful Resources
jQuery Examples - focus( )
Description
The focus() method triggers the focus event of each matched element.
Syntax
Here is the simple syntax to use this method −
selector.focus()
Parameters
None
Example
Following is a simple example showing the usage of this method. Here it triggers the focus event of each matched element −
<html> <head> <title>The jQuery Example</title> <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type = "text/javascript" language = "javascript"> function setFocus(){ $("#result1").focus(); } function removeFocus(){ $("#result1").blur(); } </script> </head> <body> <form name = "sampleForm"> <label>Enter Name: </label><input type = "text" id = "result1" title="Enter Name" value = "" ></input><br/><br/> <input type = "button" value = "Focus" onclick="setFocus();"/> <input type = "button" value = "Remove Focus" onclick="removeFocus();"/> </form> </body> </html>
This will produce following result −
jqueryexamples_events.htm
Advertisements
To Continue Learning Please Login
Login with Google