4

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

2 Answers 2

6

You need to call the function too.

functionsArray[i](); 
answered Oct 19, 2012 at 9:55
Sign up to request clarification or add additional context in comments.

Comments

2

use $.each

demo

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.