Question

Trying to increment numbers with a click, you can see by clicking my jsfiddle the issue that I am having, first two clicks register 0 and then the numbers increase 10 at a time afterwards

http://jsfiddle.net/jamcrowe/LvwDb/1/

var online = 0;
var creative = 0;
var technical = 0;
var analyst = 0;
var managerial = 0;

function  me() {
    $('#one').click(function(){
        creative +=5;
        online ++;
        managerial ++;
    });
    $('#two').click(function(){
        creative +=5;
        online ++;
        managerial ++;
    });
    $('#three').click(function(){
        creative +=5;
        online ++;
        managerial ++;
    });
    alert(creative, online, managerial);
}
Was it helpful?

Solution

You are binding the events in jQuery AND in the DOM. I'm not entirely sure what you're looking for but I'm guessing it's something like this: http://jsfiddle.net/wnfBn/

var online = 0;
var creative = 0;
var technical = 0;
var analyst = 0;
var managerial = 0;

$('#one,#two,#three').click(me);
function me() {
    creative += 5;
    online++;
    managerial++;
    alert(creative + ':' + online + ':' + managerial);
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top