0

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?

AuxTaco
  • 4,883
  • 1
  • 12
  • 27
Pierre Debroux
  • 37
  • 1
  • 10

1 Answers1

2

You don't need to put quotes into the strings, just concatenate the strings normally.

$("#jour" + i)

The quotes are part of the literal string syntax, they're not actually in the strings themselves.

Barmar
  • 741,623
  • 53
  • 500
  • 612