I would like to use the value from i
to build a new ID to use in my scrollto
function, but it doesn't work.
$('.calendar').each( function(i){
$(this).attr('id',i).css({'margin-left':'2.5px'}).text(i+5).on('click',function(){
var rr="$('"+"#jour"+i+"')"
alert(rr)
$(".layerJour").scrollTo(rr, {duration:300})
})
});
When I use an alert, it works exactly as I want:
var rr="$('"+"#jour"+i+"')"
alert(rr)
but when used here it's not working:
$(".layerJour").scrollTo(rr, {duration:300})
If I do the following, it works, which is strange because it uses exactly the same name that I have when I use alert
.
$(".layerJour").scrollTo($('#jour1'), {duration:300})
What's going wrong?