How can I grab a value from an array and call it within .append()?
In this code, the array I'm trying to pull content from is titles, and append it to the list item with the class .activeSlide. However, I get UNDEFINED on hover instead.
$(document).ready(function() {
var titles = ["Title 1", "Title 2", "Title 3"];
$("#slideshow").before("<ul id='slideshow-nav'></ul>")
.cycle( {
fx: "scrollVert",
rev: "scrollVert",
speed: 600,
timeout: 0,
pagerEvent: "mouseover",
pager: "#slideshow-nav",
pagerAnchorBuilder: function (index) {
return "<li>" + titles[index] + "</li>";
}
});
$("#slideshow-nav li").hover(function(index) {
$(this).parent().children(".activeSlide").append("<a href='#'>" + titles[index] + "</a>");
}, function () {
$("a").remove();
});
});
titles[i]whereiis 0, 1 or 2 (the index of your array).activeSlideclass.