This problem is about passing parameters between functions(define neighbour elements and acess these elements)
Here is some HTML

<ul class="listing">
			<li><a href="imgs/eli.jpg" id="1" class="lightbox" onclick="defineNeighbours(this.id);"><img src="thumbs/eli_t.jpg" width="150" height="100" class="images" /></a></li>
			<li><a href="imgs/ggallin.jpg" id="2" class="lightbox" onclick="defineNeighbours(this.id);"><img src="thumbs/ggallin_t.jpg" width="150" height="100" class="images" /></a></li>
			<li><a href="imgs/jontarata.jpg" id="3" class="lightbox" onclick="defineNeighbours(this.id);"><img src="thumbs/jontarata_t.jpg" width="150" height="100" class="images" /></a></li>
</ul>

This Javascript function is about getting the neighbours(next and previous) of given element.

function defineNeighbours(id){
  var nextimages = document.getElementById(++id);
  var backvalue = --id;
  var previmage = document.getElementById(--id);
  alert(nextimages);
  alert(previmage);
}

Then I need to pass the nextimages and previmage variables to the next function. This function should acess these elements.

function nextimage(nextimages){
$('<img src="nextimages"/>')
}

If, as the code in nextImage implies, you propose to use jQuery, then the door is open to doing this far more efficiently than with onclick handlers in the HTML.

For example, $items = $("li.lightbox a") selects all the links in the unordered list.

You then have a jQuery object which can be enquired to discover for any link, the previous and next links for whatever purpose you have in mind.

Alternatively, install something ready-written; see here for some ideas.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.