mercredi 6 juillet 2016

How to link all buttons to another page using onclick class or by tagname

I have a problem where I cant seem to get all the buttons on my page to link to another page, it does work with an ID or using a specific element for example:document.getElementsByTagName("button")[0].onclick But doing document.getElementsByTagName("button").onclick (so all buttons) or doing document.getElementsByClassName("theButtons").onclick doesnt work. My Javascript code: window.onload = function(){ document.getElementsByTagName("button").onclick = function () { location.href = "../index.html"; }; }; <button class="theButtons">click me</button> <button class="theButtons">click me</button> <button class="theButtons">click me</button>

Aucun commentaire:

Enregistrer un commentaire