Posts

Showing posts with the label event-listener

How to show specific text if one specific checkbox is checked among bunch of unique checkboxes

How to show specific text if one specific checkbox is checked among bunch of unique checkboxes I have a specific task to do, and I'm not sure what is the best way to do it. I have around 60 unique checkboxes and when clicked, display some text on their right side (tied to that clicked checkbox). I have done it with 64 specific eventListeners , but I'm not sure that this is the best way: I would like to simplify the code. eventListeners So, for example, I have bunch of checkboxes in a label that is: test , test1 , test2 and so on. And when I click on test checkbox, that the text: "hello world" can appear, if test1 is checked, text: "One 2 three" can appear, if test2 is checked, text: "I've done it" can appear, but if none of them is selected, texts will not be displayed. test test1 test2 test test1 test2 This is the code, one event listener I have now: var forSale = document.querySelector('#for_sale'); var forSaleEmail = document.que...