jQuery Examples - click( )
Description
The click() method triggers the click event of each matched element.
Syntax
Here is the simple syntax to use this method −
selector.click()
Parameters
None
Example
Following is a simple example showing the usage of this method. Here it triggers the click 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">
$(document).ready(function() {
$("#clickButton1").click(function(){
alert("click event occurred");
});
});
function clickFirstButton(){
$("#clickButton1").click();
}
</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" id = "clickButton1" value = "Click Me!" /> <input type = "button" id = "clickButton2" value = "Click First Button!" onclick="clickFirstButton();" />
</form>
</body>
</html>
This will produce following result −
jqueryexamples_events.htm
Advertisements