[Javascript] Accessing a nested Anchor element.

Mike Dougherty mdougherty at pbp.com
Mon Apr 18 12:35:28 CDT 2005


If there is only one on anchor in this cell, you _could_ do this: (untested)

var loContainer = document.getElementById("G23520050328_name")
if (loContainer) {
   var loAnchors = loContainer.getElementsByTagName("A")
   if (loAnchors) { 
     var loA = loAnchors.firstChild 
     if (loA) { 
       [do something] 
       }
     }
   }

If there is any potential that there could be multiple <a> per <td> you could iterate the 
loAnchors collection and act accordingly.


Why not put the id on the <a> tag that you want to reference?



On Mon, 18 Apr 2005 09:49:53 -0700
  "Ian Skinner" <ian.skinner at bloodsource.org> wrote:
>Assume the following HTML markup.
>
><td id="G23520050328_name">
>	<a href="..." title="..." onClick="...">CalHFA</a>
></td>
>
>In a JS function there is basically this assignment. [This of course is done dynamically but I am 
>simplifying for this question.]
>
>var name_cell = document.getElementById("G23520050328_name");
>
>What I would like to know, what is the simplest yet cross browser compatible method to access the 
><a>nchor element in the "name_cell" reference in order to set a style property on the anchor? 
> The color property in my current requirement.  This can hopefully be done with little to no 
>extra HTML since there are hundreds of these cells.
>
>TIA
>
>
>--------------
>Ian Skinner
>Web Programmer
>BloodSource
>www.BloodSource.org
>Sacramento, CA
> 
>"C code. C code run. Run code run. Please!"
>- Cynthia Dunning
>
>Confidentiality Notice:  This message including any
>attachments is for the sole use of the intended
>recipient(s) and may contain confidential and privileged
>information. Any unauthorized review, use, disclosure or
>distribution is prohibited. If you are not the
>intended recipient, please contact the sender and
>delete any copies of this message. 
>
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>__________________________________________________________
>This message was scanned by ATX
>1:18:24 PM ET - 4/18/2005




More information about the Javascript mailing list