+ 1

Why this click counter by class-name is not working.

I created a project that: When the user clicks on the ring, the user will see how many times the user has clicked. project link: https://code.sololearn.com/WzLObhteFHfH/?ref=app Problem: It works when I use ID but not when I use classes. Why? Please explain.

3rd Nov 2020, 11:16 AM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar
10 ответов
+ 5
It is because getElementsByClassName returns a nodelist, not a single node like getElementById does. To access the node (the first node), you need to use getElementsByClassName[0].html...
3rd Nov 2020, 11:40 AM
Russ
Russ - avatar
+ 3
Create a for loop and access each one separately.
3rd Nov 2020, 11:47 AM
Russ
Russ - avatar
+ 3
To make all 3 clickable you need to add the onclick="numup()" attribute to the other two in your HTML tab.
3rd Nov 2020, 3:34 PM
Russ
Russ - avatar
+ 2
By this first box will work How can all node work?
3rd Nov 2020, 11:45 AM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar
+ 2
But all circle work in one click,how to fix plz give me ans with code plz plz plz
3rd Nov 2020, 11:59 AM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar
+ 2
When i click first class all class show num
3rd Nov 2020, 12:00 PM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar
+ 2
I no longer understand your question. I thought that you wanted all circles to change when you click the top one. That is what is happening with your code right now. If this is not right, can you please explain fully what you want to happen?
3rd Nov 2020, 12:12 PM
Russ
Russ - avatar
+ 2
I want to make 3 click counter But separate
3rd Nov 2020, 3:30 PM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar
+ 1
There are 3 things to do: Task 1: User has to click 1st circle 33 times. Task 2: User has to click 33 times 2nd circle. Task 3: The user has to click 33 times on the 3rd circle. It will show how many times the user has clicked
3rd Nov 2020, 4:17 PM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar
+ 1
Plz tell me how can i fix my code for this 👆👆👆
3rd Nov 2020, 4:18 PM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar