I have a hidden input element that I am using as a counter to use to name more input elements generated by JavaScript. To get the value of the counter i use
parseInt($('#counter').val());
However I use this code snippet several times in my code, so I thought it would be good to put it in a function
function getCounter(){
parseInt($('#counter').val());
}
this always returns undefined, while running just the code snippet returns the correct value. This happens in several ways that I tried defeining the function, as a function inside a $(function(){}), as a global function etc. How do I fix the scoping?