Javascript Multiple Buttons With Same Class You Must Want To Target All Div Elements Which Class Starts ( ^=) With "button": (Note That You Can Do It In The CSS Too!) Var AllButtons = Document.querySelectorAll ('div [class^=button]'); Console.log ("Found", AllButtons.length, "div Which Class Starts With “button”."); For (var I = 0; I < AllButtons.length; I++) { AllButtons [i].addEventListener ('click', Function () { Console.clear (); Console.log ("You Clicked:", This.innerHTML); }); } It Works Well But I Need To Be Able To Have Multiple Buttons With The Same Class Or Name Available. Although I Have Seen Examples Of This, I Cannot Get It To Function Properly. Function Q1a1 () { Var Q1a1button = Document.getElementById ("q1answer1"); If (q1a1button.addEventListener) { Q1a1button.addEventListener ("click", Function () { Q1answer1 ();}, False); } Else If (q1a1button.attachEvent) { Q1a1button.attachEvent ("onclick", Function () { Q1answer1 ();}); } }; If (window. Var AllButtons = Document.querySelectorAll ('div [class^=button]'); Console.log ("Found", AllButtons.length, "div Which Class Starts With “button”."); For (var I = 0; I < AllButtons.length; I++) { AllButtons [i].addEventListener ('click', Function () { Console.clear (); Console.log ("You Clicked:", This.innerHTML); }); } Javascript Click Event On Multiple Elements With Same Class. Event For Multiple Elements With The Same Class Name, As Its Name Suggests Document.getElementsByClassName Returns A List Of Elements, With The Hover As Their ClassName, So You Can Do It Like: The Click Event Is Fired When A Pointing Device Button (usually A Mouse's Primary Button) Is This Allows You To Use .siblings("button") To Select The Clicked Button's Counterpart : $(".updateStatus").click(function { $(this) .addClass(($(this).val() === "complete") ? 'green' : 'orange') .siblings("button").removeClass("green Orange"); }); The .each() Loop Vanishes. Let Btns = Document.querySelectorAll ('button'); //get All Buttons Btns.forEach ( Btn => { Btn.addEventListener ('click', F); } That Will Find All The Button Elements On The Page, Loop Through Them And Add A Click Listener To All Of Them To Call The Same Function. Then The Function Needs To Know Who Called It. 1. GetElementsByClassName Return An Array Of Elements. You Have To Iterate Them And Update Their Style One By One. Var Elements = { Design: Document.getElementsByClassName ("design"), It: Document.getElementsByClassName ("it"), Other: Document.getElementsByClassName ("other") }; Function Toggle (type) { Object.keys (elements).forEach (function (key) { Var Els = Elements [key]; Var State = "none"; If (key === Type) State = "block"; For (var I = 0; I < Els.length; I++) { Els [i].style. To Style Multiple Attributes Of Our Button Using A Style Class, We Would Write ClickMeButton.className = 'myStyleClassName' Instead. Document.body.appendChild(clickMeButton) Appends To The Body Of The Document As A Child. Well Organized And Easy To Understand Web Building Tutorials With Lots Of Examples Of How To Use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML And More. Insert The Current Time Your Zap Runs Into A Field Add Event Listener To Multiple Buttons With The Same Class.