Skip to content
Advertisement

How to get the value of checked checkbox in vanilla JavaScript?

I am working on this snippet. Why am I not able to get the value of any checked checkbox with class .shapes?

JavaScript
JavaScript

Advertisement

Answer

You can simply use querySelectorAll method and use forEach method to check which checkbox was clicked using addEventListener with change function in it.

Edit: If you want to get the value of checkbox when checked you can checked property and then display its value.

Live Demo

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement