Triggering nested javascript functions
<p>I'm relatively new to javascript and I've been banging my head against an issue all day - I'm hoping someone can point me in the right direction.</p>

<p>I have a PHP script that does a slideshow. I have NEXT and PREVIOUS buttons which contain dynamic links to another javascript function. I'm hoping to find a way of triggering them with the arrow keys on the keyboard.</p>

<p>So far, I've found a way of making the arrow keys launch particular URLs but I'm struggling a bit now. The target URLs change as a result of hiding and showing DIVs on the page. So I think I need to do one of the following:</p>

<p>Trigger this code with URLS constructed within PHP variables later in the main body of the page - without refreshing the page:</p>

<pre><code>&lt;script type="text/javascript"&gt;

$(document).keydown(function(e){

 //e.which is set by jQuery for those browsers that do not normally support e.keyCode.
 var keyCode = e.keyCode || e.which;

if (keyCode == 37)
 {
 window.location = 'http://www.domain.com/previous-image.jpg';
 return false;
 }

 if (keyCode == 39)
 {
 window.location = 'http://www.domain.com/next-image.jpg';
 return false;
 }

});

&lt;/script&gt;
</code></pre>

<p>...or I need to find a way of triggering a link within a DIV of a particular name - but only if the DIV is not hidden.</p>

<p>Any pointers would be appreciated.</p>

<p>Edit: 10/10/12</p>

<p>Thanks for everyone's help so far. I now understand a bit more and I can perhaps be clearer with what I'm trying to achieve.</p>

<p>I have a page which has 5 DIVs - 4 of which are hidden. Each is identical except for the image displayed in it and I use the following code to hide or show the various DIVs: <a href="http://jsfiddle.net/edzpgt/ZhjRc/12/" rel="nofollow">http://jsfiddle.net/edzpgt/ZhjRc/12/</a></p>

<p>I need to use arrow keys to navigate the pages so I'll add some Jquery for this as we've already discussed: <a href="http://jsfiddle.net/edzpgt/b2bWz/3/" rel="nofollow">http://jsfiddle.net/edzpgt/b2bWz/3/</a></p>

<p>I think I have two issues:
1. I'm not sure I have the syntax correct in order to make sure I'm only using the arrow key links from the visible DIV.
2. I don't think I'm setting or using the next/previous page number variable correctly in order to get the right desintation URL passed to the Jquery.</p>

<p>Can anyone help please?</p>
