0 points

Add event listener to multiple buttons with the same class


dashboard

Mon Jun 29 2020 23:11:09 GMT+0000 (UTC)

Posted by @mishka #javascript

    btns = document.getElementsByClassName("saveBtn");
    for (var i = 0; i < btns.length; i++) {
        btns[i].addEventListener("click", function () {
			//Add function here
        });
    }
content_copy Copy

This works for an array of elements with the same class.