Why is my function running multiple times?
var s,
getData = {
settings: {
gender: $("input[name='gender']"),
age: $("input[name='age']")
},
init: function() {
s = this.settings;
this.getInput();
},
getInput: function() {
for (i in s) {
s[i].on("click", function() {
s[i].off();
console.log(this.getAttribute('value'))
});
}
},
};
What I find odd is that when I don't click the same input twice it only runs once. For instance if I click 'male' and then 'female' it would show in the console
(1) male
(2) female
which logically makes sense to me, if I clicked 'male' 5 times then I get
(14) male
and it just gets larger and larger.
EDIT: JSFiddle If you open console you can see what happens