Passing parameters in this case
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"/>')
}
george61
Junior Poster in Training
59 posts since Jul 2010
Reputation Points: 10
Solved Threads: 6
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
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372