DOM change font color by using addEventListener

I am a beginner of JS and HTML.
I encounter a problem with changing the font color by using addEventListener

here is my part of HTML code

<form>
   <input type = 'color' class = 'color'>
</form>

here is my js code.

// this is for class color 
const color = document.querySelectorAll('.color');

// I have 2 div block which contains messages.

const showTextBox = document.querySelectorAll('.mtext1');

// for each message, they correspond to the different color boxes.

color.forEach((element, index) => {
  element.addEventListener('click', function (e) {
    console.log(e)

    showTextBox[index].style.color = color[index].value;
  })
});

the situation I encounter is when I click the color box, it pops up the Palette, and then you have to "click" again for choosing the color. However, that addEventListener only available for the first click.

What I thought is maybe I can use nested addEventListener?
or does javascript has a more efficient way to change color dynamically(or responsively) to solve double click situation?

132 thoughts on “DOM change font color by using addEventListener”

  1. Pingback: cialis overdose
  2. Pingback: viagra 100
  3. Pingback: sildenafil citrate
  4. Pingback: sildenafil prices
  5. Pingback: levitra cvs
  6. Pingback: doxycycline 100mg
  7. Pingback: lasix side effects
  8. Pingback: xenical pill
  9. Pingback: priligy singapore
  10. Pingback: tizanidine tablets
  11. Pingback: cipro dosage dog
  12. Pingback: cialis 20mg pills
  13. Pingback: online viagra
  14. Pingback: amoxicillin 500mg
  15. Pingback: neurontin pfizer
  16. Pingback: plaquenil generic
  17. Pingback: prednisone 5093
  18. Pingback: modafinil sale
  19. Pingback: ivermectin 3
  20. Pingback: ventolin spray
  21. Pingback: cost of zithromax
  22. Pingback: gabapentin 3000 mg
  23. Pingback: azithromycin pill
  24. Pingback: tamoxifen 50 mg
  25. Pingback: aralen 20 mg
  26. Pingback: molnuprivair
  27. Pingback: latisse generic
  28. Pingback: lumigan glaucoma
  29. Pingback: chloroquine 150 mg

Leave a Comment