How can I access the content of an HTML element from a node list?
pI can't seem to access the content of certain elements and I think it
must be because of the syntax I'm using. I'm trying to write and overwrite
members of a getElementsByClassName list. I understand that it is a
nodeList and not an array, but I still can't figure it out. Here's what I
have/have tried:/p pHTML:/p precodelt;span class=myclassgt;Textlt;/spangt;
lt;span class=myclassgt;Text2lt;/spangt; /code/pre pJS:/p precodevar
spanarray = document.getElementsByClassName(myclass); //I've tried all of
the following (for the record, I thought either 2 or 5 would work)
spanarray[0] = Replacement text; spanarray[0].innerHTML = Replacement
text; spanarray.item(0) = Replacement text; spanarray.item(0).innerHTML =
Replacement text; spanarray.item(0).nodeValue = Replacement text;
/code/pre pI'd really appreciate if somebody could point me in the right
direction. Thanks./p
No comments:
Post a Comment