Reputation: 1582
I've got many sets of divs. e.g.: furniture1, furniture2, furniture3....
, stationary1, stationary2, stationary3...
, etc...
I need to have a unique tooltip for each ID. What is the easiest way to do this?
e.g.:
$("#furniture1").tooltip({ title : '$560' });
$("#furniture2").tooltip({ title : '$785' });
$("#furniture3").tooltip({ title : '$325' });
Is it possible to do this using 2 arrays (ID array and TITLE array)?
EDIT:
Using JSON to populate arrays:
var tt;
$.ajax({url: '/toolt.json'}).done(function(t) {
tt = t;
//how to combine with a loop?
});
Upvotes: 0
Views: 185
Reputation: 16068
Sure, just go through ids and put the tooltip:
var ids = ["furniture1", "furniture2", "furniture3"]
var titles = ["$560", "$785", "$325"]
for(var i = 0; i < ids.length;i++ ){
$("#"+ids[i]).tooltip({title:titles[i]})
}
To make these 2 arrays from the json:
var ids = [], titles = []
for(var i=0; i < t.length;i++){
ids.push(t[i][0]);
titles.push(t[i][1])
}
Upvotes: 1