Reputation: 3
This is a gallery I have created (with some help) for my website. I would like to incorporate an unordered list (in a drop down style) between the Next and Back buttons however, I am not sure how to append such code to the jQuery. Any help would be greatly appreciated; thanks!
<a href="#" id="back"> Back </a> - <a href="#" id="next"> Next </a></h2></center>
<center> <img src='gallery/img01.jpg' id='gallery'>
<center><h4><a href="#" id="back"> Back </a> - <a href="#" id="next"> Next </a>
<script>
var image = [];
var num = 0;
function fillImgList()
{
for(var i = 1; i <= 34; ++i)
{
image.push("gallery\\img" + (i < 10 ? "0" : "") + i + ".jpg");
}
}
fillImgList();
$(function()
{
$("#next").click(function() { galleryNext(); });
$("#back").click(function() { galleryPrevious(); });
});
function galleryNext()
{
num++;
$("#gallery").attr('src', image[num % image.length]);
}
function galleryPrevious()
{
num--;
if(num < 0)
{
num = image.length-1
}
$("#gallery").attr('src', image[num % image.length]);
}
</script>
Upvotes: 0
Views: 53
Reputation: 393
One thing you could do is use the insertAfter()
or after()
functions. You can see in this example: http://jsfiddle.net/83CSK/
You generate the list as a string in javascript then you pass it through as a selector to jquery which will create the dom element and place it after the selector.
Docs on this function can be found here: http://api.jquery.com/insertafter/
Upvotes: 1