Select one element and mark it and unmark all other elements using JavaScript
This is how you select one element and mark it somehow and unmark all other elements using JavaScript. You have an unlimited list of rows, maybe div tags or table tr rows. On each row you have a button and you when you click that button you want some action to take place and one of those actions maybe is mark up or show some element in that row, but at the same time you want to unmark or hide all other elements.
You maybe have tried to use getElementsByClassName and found out that its not supported in all browser. One solution is to getElementsByName.
//var markFooter = document.getElementsByName('r2d2-check'); //Not in IE
var markFooter = getElementsByName_iefix("div", "r2d2-check");
for(var r=0; r < markFooter.length; r++){
markFooter[r].className = "r2d2-check-none";
}
var markFooter = document.getElementById('r2d2-check-'+delta);
markFooter.className = "r2d2-check-ok";
function getElementsByName_iefix(tag, name) {
var elem = document.getElementsByTagName(tag);
var arr = new Array();
for(i = 0,iarr = 0; i < elem.length; i++) {
att = elem[i].getAttribute("name");
if(att == name) {
arr[iarr] = elem[i];
iarr++;
}
}
return arr;
}
Soorce: http://www.dreamincode.net/code/snippet293.htm
[/codefilter_code]
Knowledge keywords: