Reputation: 557
how to call jquery click function from other jquery function.
i tried by using trigger function it is not working.
Here is my jquery function
$('#index1').click(function(event){
$('#index2').trigger('click');
});
$('#index2').click(function(event){
alert("Hello");
});
i want to call #index2 function from #index1 function.
Upvotes: 0
Views: 84
Reputation: 5482
Here is the working example:
Be sure you have added a jquery library
$('#index1').click(function(event){
$('#index2').trigger('click');
});
$('#index2').click(function(event){
alert("Hello");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<h2 id="index1">
Index 1
</h2>
<h4 id="index2">
Index 2
</h4>
Upvotes: 2