Click here to Skip to main content
15,170,971 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 1501261727-Mar-21 22:40
MemberMember 1501261727-Mar-21 22:40 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 23:49
MemberMember 150126178-Apr-21 23:49 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Richard Deeming28-Mar-21 23:29
mveRichard Deeming28-Mar-21 23:29 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 23:49
MemberMember 150126178-Apr-21 23:49 
QuestionRedirect with (Page Visibility API) Pin
ab smine19-Mar-21 11:38
Memberab smine19-Mar-21 11:38 
QuestionNode-Schedule Module Can't Cron Job Scheduled Long Time Pin
Barış KAHRAMAN19-Mar-21 11:02
MemberBarış KAHRAMAN19-Mar-21 11:02 
QuestionCalculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 4:31
MemberKrasimir Dermendzhiev16-Mar-21 4:31 
AnswerRe: Calculation in javascript Pin
Richard Deeming16-Mar-21 5:39
mveRichard Deeming16-Mar-21 5:39 
You've attached two click handles to .firstDigit li, and none to .secondDigit li.

The handler you've attached isn't going to sum anything; it simply takes the attribute from the clicked element, and puts it in the total element.

Try something more like this:
JavaScript
const updateTotal = function(){
	let total = 0;
	
	$("ol > li[data-value].active").each(function(){
		const value = parseInt(this.getAttribute("data-value"));
		if (!isNaN(value)) { total += value; }
	});
	
	$("#total").html(total);
};

$(document).on("click", "ol > li[data-value]", function(){
	const me = $(this);
	me.closest("ol").find("li").removeClass("active");
	me.addClass("active");
	updateTotal();
});
Demo[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 22:36
MemberKrasimir Dermendzhiev16-Mar-21 22:36 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev30-Mar-21 5:22
MemberKrasimir Dermendzhiev30-Mar-21 5:22 
QuestionJavascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027614-Mar-21 22:50
MemberMember 1510027614-Mar-21 22:50 
AnswerRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming14-Mar-21 23:39
mveRichard Deeming14-Mar-21 23:39 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027615-Mar-21 0:11
MemberMember 1510027615-Mar-21 0:11 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming15-Mar-21 0:29
mveRichard Deeming15-Mar-21 0:29 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027615-Mar-21 8:56
MemberMember 1510027615-Mar-21 8:56 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming15-Mar-21 23:31
mveRichard Deeming15-Mar-21 23:31 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027616-Mar-21 7:49
MemberMember 1510027616-Mar-21 7:49 
Questionif statement not working Pin
chizzy4211-Mar-21 8:53
Memberchizzy4211-Mar-21 8:53 
AnswerRe: if statement not working Pin
NotTodayYo11-Mar-21 9:24
MemberNotTodayYo11-Mar-21 9:24 
AnswerRe: if statement not working Pin
W Balboos, GHB11-Mar-21 9:45
mveW Balboos, GHB11-Mar-21 9:45 
GeneralRe: if statement not working Pin
chizzy4213-Mar-21 5:03
Memberchizzy4213-Mar-21 5:03 
GeneralRe: if statement not working Pin
Member 1510027615-Mar-21 9:15
MemberMember 1510027615-Mar-21 9:15 
GeneralRe: if statement not working Pin
chizzy4217-Mar-21 3:28
Memberchizzy4217-Mar-21 3:28 
QuestionBeginner 5 Project idea Pin
Member 1373246628-Feb-21 15:29
MemberMember 1373246628-Feb-21 15:29 
AnswerRe: Beginner 5 Project idea Pin
Richard MacCutchan28-Feb-21 22:37
mveRichard MacCutchan28-Feb-21 22:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.