document.getElementsByTagName('img').style.border = '0';
document.getElementById(“ca1”).style.border=“2px red solid”;
document.getElementById(“ca5”).style.border=“2px red solid”;
I’m using the above in a function. I expect all the images to revert to no border, but nothing happens. Later within this function is setting a border around the selected images. (That works if I remove the top line.) But I want any other image borders to be reset to 0 first.
But in more general terms - getElementsByTagName returns an array-like object; you cannot apply a style (or a class) to such an object. You have to walk through the result of your search and apply it to each in turn.