Currently it appears you are running the each()
function only a single time when this script first loads. As such, you should not expect it to pick up any changes that are made dynamically to the DOM.
You then set up an onclick function to compare the counter
value (which would always be the last calculated value for the last button), against what may be a different button. So in essence after the each()
is run counter
has a static value to which all buttons will be compared during click()
. I am guessing this is not what you intended.
You should probably just calculate the size of the ol
selection in the click()
function as you are really gaining nothing from using this counter
variable.