I have a button which adds a paragraph each time it is clicked. In my code i have a function called addPara(count), and i have a counterstart variable. how can i pass this counterstart variable to me function?
views:
49answers:
2thanks but not what i needed perhaps my question is too vague. The addPara() function should have (at least) one argument passed to it – the counterStart variable....
Sam
2010-09-04 00:27:00
Yeah, I'm passing the `counterstart` variable to `addPara`.
mathepic
2010-09-04 00:39:55
+2
A:
If you mean that you're not sure how many arguments will be passed, you can reference any and all argument via the arguments collection inside the function.
function addPara() {
console.log(arguments); // "arguments" is a collection of the arguments.
if(arguments[0] === undefined) {
// do something and return if no arguments were given
return false;
}
// otherwise loop through the arguments passed
for( var i = 0, len = arguments.length; i < len; i++ ) {
// do something with arguments[ i ];
}
}
patrick dw
2010-09-04 00:45:07
This question is so ambiguous that I question if its even worth answering. +1 for the effort.
mathepic
2010-09-04 00:47:47