[thelist] set/getAttribute is not a function?
Jonathan Snook
jonathan.snook at gmail.com
Fri Jun 15 18:47:02 CDT 2007
On 6/15/07, Jon Hughes <hughesj at firemtn.com> wrote:
> var image =
> document.getElementById(id).getElementsByTagName('img');
> alert(image.getAttribute('src'));
> alert(img);
> image.setAttribute('src',img);
> }
>
> For some reason, getAttribute and setAttribute give me the following
> error:
>
> getAttribute is not a function
> setAttribute is not a function
getElementsByTagName returns an array (I believe technically a
NodeList). So, if you know there's only one image that'll be returned
by that call, just add [0] to the end (the first element in the
array).
var image = document.getElementById(id).getElementsByTagName('img')[0];
-Jonathan
More information about the thelist
mailing list