Short, quick version: Is there a way of simulating a mouseclick in a div from a keypress?
In other words, if I press 2, I want it to simulate me actually having clicked in the div
<div id="jplayer_next2"><a href="#">next</div>
Long version (for anyone wondering "WHY?")
Using the jplayer jquery plugin:
For some reason (and after 2 days I've given up trying to find out) I can't seem to directly call the function which is defined right there on the page:
So I've settled for copying the div it is defined in:
case 51 : <simulate a click on #jplayer_next2>;break;
Any ideas are hugely appreciated - this has been a long few nights and many grey hairs!
In other words, if I press 2, I want it to simulate me actually having clicked in the div
<div id="jplayer_next2"><a href="#">next</div>
Long version (for anyone wondering "WHY?")
Using the jplayer jquery plugin:
For some reason (and after 2 days I've given up trying to find out) I can't seem to directly call the function which is defined right there on the page:
- function playListNext() {
- var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
- if( index > 0 ) {
- playListChange( index );
- }
So I've settled for copying the div it is defined in:
As it appears that once you've clicked one element, you can't click
the same named element further down, to get the tabindex keypresses
going, I've done the following:
$("#jplayer_previous").click( function() {
playListPrev();
return false;
});
$("#jplayer_next").click( function() {
playListNext();
return false;
});
$("#jplayer_previous2").click( function() {
playListPrev();
return false;
});
$("#jplayer_next2").click( function() {
playListNext();
return false;
});
So now, I have the player further down the page, and at the top, I
have
<div id="jplayer_previous2" ><a href="#">previous</a></div>
<div id="jplayer_next2"><a href="#">next</div>
All good so far for clickable links BUT... there MUST be a way of
simulating a mouse click in a div, so I can carry on with the
accesskeys (the only thing holding up going live).
I've had my head buried in various docs about jquery "click" and
javascript "onclick" etc, but nothing seems to suit. So what I need
is a function that will simulate having clicked in<div
id="jplayer_next2"><a href="#">next</div>, which then calls
playListNext()
- $(document).keypress(function(evt)
- {
- var keyCode = 0;
- if (evt)
- {
- keyCode = evt.keyCode || evt.which;
- }
- else
- {
- // For IE
- keyCode = window.event.keyCode;
- }
- switch (keyCode)
- {
- case 49 : $("#jquery_jplayer").jPlayer("play");break; //1
- case 50 : $("#jquery_jplayer").jPlayer("pause");break; //2
- case 51 : $("#jquery_jplayer").playListNext;break; //3
- }
- });
case 51 : <simulate a click on #jplayer_next2>;break;
Any ideas are hugely appreciated - this has been a long few nights and many grey hairs!
1