I'm using a mixture of d3.js and jQuery to create a visualisation. I have 3 functions that I'm trying to put into an array and then execute one after the other but I don't think I'm doing it correctly as when I click "play" nothing happens. Here's my code:
var functionsArray = [oct12,oct13,oct14];
$('#play').click(function(){
for (var i = 0; i < functionsArray.length; i++){
functionsArray[i];
}
I'll put up a jsfiddle shortly...
asked Oct 19, 2012 at 9:52
zik
3,10511 gold badges46 silver badges63 bronze badges
2 Answers 2
You need to call the function too.
functionsArray[i]();
answered Oct 19, 2012 at 9:55
Dogbert
224k43 gold badges419 silver badges417 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
use $.each
var functionsArray = [oct12,oct13,oct14];
$(functionsArray).each(function(key, val){
val();
});
function oct12(){
alert('oct12');
}
function oct13(){
alert('oct13');
}
function oct14(){
alert('oct14');
}
answered Oct 19, 2012 at 9:58
Pragnesh Chauhan
8,49410 gold badges46 silver badges58 bronze badges
Comments
lang-js