0

I am waiting for a number from server, once I get the number, I want to find an according id name to change the background of that div.

So, I created a set of key and value

var timelineKeys = {
        "4": "btn_no_1",
        "5": "btn-no-2",
        "6": "btn-no-3",
        "7": "btn-no-4",
        "1": "btn-no-5",
        "2": "btn-no-6",
        "2": "btn-no-7",
    }

in my $.ajax, I get the variable from server and I call it 't', 't' will be one of the key numbers there, but how can I get text "btn-no-.." dynamically using this variable? timelineKeys.t seems doesn't work.

Thanks

the_summer_bee
  • 483
  • 4
  • 10
  • 23

1 Answers1

0
timelinekeys[t]

is the syntax when the property name you want to access is contained in a variable, t in your case; for more information refer to this question: Difference between using bracket (`[]`) and dot (`.`) notation

Community
  • 1
  • 1
Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
  • Hi,thanks, can I ask one more question? now I get this idName(=timelineKeys[t]), and I put it into jquery: $("#"+idName).css(...), but it didn't work, what have I done wrong? – the_summer_bee Jul 10 '13 at 16:04
  • Seems fine, provided you wrote `idName = timelineKeys[t]`, if you still have problems I think you should create a new question – Alberto Zaccagni Jul 10 '13 at 16:22