I have this simple code for keydown. At the moment is fading in div1. I am looking for a code which will press a button?. I know I have to add onClick event on the button but I tried couple of ways which didn't gave me any results.
jQuery(document).one('keydown', 'g',function (evt){
$("#Div1").fadeIn();
return false;});
The button source is: (Which on click it does show's me #Div1 again. I want to add the same for the Div1.):
<ul id="button">
<li><a class="btn1" id=btn1 href="开发者_如何学编程#Div1"></a></li>
</ul>
You probably think why would I want that? The reason is that Div1 is a form which on button click makes some animations where on FadeIn it doesn't. Thanks alot.
Try this:
jQuery(document).one('keydown', 'g',function (evt){
$("#btn1").click();
});
You can use jquery trigger to fire the button click. Trigger API
It would look something like this.
$("#btn1").trigger('click');
Try
$("#btn1").trigger("click");
A similar question has been posted:
Is there a jQuery Click method?
精彩评论