In this scenario, I am attempting to calculate values based on the active span element. My complete code is available on JSFiddle. The span is not editable and I have assumed that the span values are 40. If a user selects a span, it will change to green color. If another span is clicked, the value of span#returndata
should be incremented by 40 (i.e., 40 + 40 = 80). With each subsequent click on a span, the total should increment by 40 (e.g., 40 + 40 + 40 = 120).
Below is the jQuery code snippet I have tried, but so far without success:
jQuery
$(".text").click(function(){
$(this).toggleClass('selected');
$(function(){
$('span#text').click(function(){
var value = 40;
var t = parseInt($(this).text());
var total = value * t;
$('#returndata').text(total);
});
});
});