How to store two click counters in variables and do some calculations with it - jquery -
I have to click on a "next" and "preview" div, with the following code, for each It is possible to store numbered clicks in a variable. Alertbox displaying results while clicking. So far, so good. But I do not know why it does not make any calculations with "Verne Counttext" and "Wear Counterpoint"!
"var countResult" is always clicking on #test div to alert the result.
var countNext = ($ ('# next'). Data ('click_count') || 0); Var countPrev = ($ ('# prev'). Data ('click_count')) 0); Var countResult = countNext - countPrev; $ ('# Next'). ('Click', function () {countNext ++; alert (countNext);}); $ ('# Prev') ('Click', function () {countPrev ++; alert (countPrev);}); $ ('# Exam') ('Click', function () {warning (countResult);}); Do you know what is wrong with it?
You need to calculate the calculation every time you click
var countNext = ($ ('# next'). Data ('click_count') || 0); Var countPrev = ($ ('# prev'). Data ('click_count')) 0); Var countResult = countNext - countPrev; $ ('# Next'). ('Click', function () {countNext ++; countResult = countNext - countPrev; warning (countNext);}); $ ('# Prev') ('Click', function () {countPrev ++; countResult = countNext - countPrev; warning (countPrev);}); $ ('# Exam') ('Click', function () {warning (countResult);});
Comments
Post a Comment