Here is my javascript:
function scrollTo(position) {
$('body').animate({
scrollTop: position
}, 500);
}
var titles = $('.title');
for(var i = 0; i < titles.length; i++) {
titles[i].click(function() {
console.log('click');
scrollTo(0);
});
}
It's supposed to select all three titles and apply a click listener that will scroll the page back to the top. Unfortunately I am not getting the message in the console nor is it scrolling.
Everywhere I have looked online has given for loops exactly like this to apply a click listener to multiple JQuery objects but for some reason it won't work for me. I'm afraid I may have made a stupid mistake but I can't find it.
$(titles[i]).click(...);for that to work. Ortitles.eq(i).click(...)titles[i]returns a DOM object