I been reading about getElmentByClassName but I cant seem to get it work in any browser, The function i have works when o call the ID name, but i would like to be able to call the classname.
Is there any way that don't include Jquery ?
This is what I have, would be awsome with some help. thanks.
<ul><li><button class="testButton">Test button</button></li></ul>
function OnButtonDown (button) {
alert("The class work")
}
function Init () {
var className = "testButton";
var button = document.getElementsByClassName(className);
if (button.addEventListener) { // all browsers except IE before version 9
button.addEventListener ("mousedown", function () {
OnButtonDown (button)
}, false);
button.addEventListener ("mouseup", function () {
OnButtonUp (button)
}, false);
}
else {
if (button.attachEvent) { // IE before version 9
button.attachEvent ("onmousedown", function () {
OnButtonDown (button)
});
button.attachEvent ("onmouseup", function () {
OnButtonUp (button)
});
}
}
}