<font face="arial" size="2">Ah so.<br /><br />I stand corrected.<br /><br />Funny, too, since I've taken to using the getElementsByTagName approach lately anyway...<br /><br /></font>
                <font face="Tahoma, Arial, Sans-Serif" size="2">
                                <b>From</b>: Paul Novitski <a href="mailto:paul@juniperwebcraft.com">paul@juniperwebcraft.com</a><br /></font>
                <br />At 9/8/2006 12:17 PM, Terry Riegel wrote:<br />&gt;If I have the following markup...<br />&gt;<br />&gt; 
<li class="anor" id="album01"><a href="album1.html">My Favorite<br />&gt;Photos (58)</a><br />&gt;<br />&gt;and... in my javascript I have...<br />&gt;<br />&gt; o=document.getElementById('album01');<br />&gt;<br />&gt;How do I reference (with the intent of changing) the content of the<br />&gt;anchor? My goal is to replace the text<br /><br />At 9/8/2006 12:49 PM, Peter Brunone wrote:<br />&gt;Wouldn't that just be o.childNodes[0].innerHTML ?<br /><br />At 9/8/2006 03:33 PM, Matt Warden wrote:<br />&gt;var li = document.getElementById('album01');<br />&gt;var anchor = li.firstChild;<br />&gt;var textNode = anchor.firstChild;<br /><br /><br />Part of the question will always be: how stable is your markup? For <br />example, if you or anyone else ever changes the HTML by inserting a <br />carriage return between the LI tag and the A, then I believe the <br />firstChild and the first childNode of LI would be a text node (the <br />carriage return) and the anchor would be its next sibling. Perhaps <br />safer would be:<br /><br />o=document.getElementById('album01');<br />var aAnchors = o.getElementsByTagName("A");<br /><br />if (aAnchors.length != 1) return alert("Help! Kwazy <br />unexpected markup!");<br /><br />Then your one and only expected anchor is aAnchors[0].<br /><br />Again, if the contents of the anchor is a single text string then it <br />will indeed be the firstChild, but if anyone ever inserts a SPAN or <br />EM then you'll have two or more childNodes.<br /><br />In the Gecko DOM Reference it suggests an iterative approach to <br />removing all the children of a parent:<br /><br />// remove all children from element<br />var element = document.getElementById("top");<br />while (element.firstChild) {<br />element.removeChild(element.firstChild);<br />}<br />http://developer.mozilla.org/en/docs/DOM:element.removeChild#Example<br /><br />With respect to innerHTML, the reference says: "Though not actually <br />a part of the W3C DOM specification, this property provides a simple <br />way to completely replace the contents of an element. ... As there is <br />no public specification for this property, implementations differ <br />widely. For example, when text is entered into a text input, IE will <br />change the value attribute of the input's innerHTML property but <br />Gecko browsers do not."<br />http://developer.mozilla.org/en/docs/DOM:element.innerHTML#Notes<br /><br />I take that to mean that using removeChild is the safer course, <br />although you might get away with using innerHTML with few complaints.<br /><br />Paul <br /><br />_______________________________________________<br />Javascript mailing list<br />Javascript@LaTech.edu<br />https://lists.LaTech.edu/mailman/listinfo/javascript<br /><br /></li>