Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

error:addEventListener is not a function, when i use getElementByClassName [duplicate]

$
0
0

This question already has an answer here:

I am new to JavaScript, and can't get this problem solved

Error : btn.addEventListener is not a function

It works when I use query selector, but not when I getElementByClassName

HTML

<input type="text" class="amount">
     <select>
                <option class="option" value="1">Good</option>
                <option class="option" value="2">Ok</option>
                <option class="option" value="3">Bad</option>
            </select>
 <button class="btn"> Calculate </button>

JavaScript

const amount = document.getElementsByClassName('amount');
const btn = document.getElementsByClassName('btn');

btn.addEventListener('click', a());

function a() {
  alert('100');
}

The alert fires off on the load of the window!


Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>