Hyperlink target to a Cell of a Table

Posted on 2004-11-17
Last Modified: 2008-03-03
Is it possible, just using HTML (or even a simple java script) to have the target of a hyperlink be a cell in a table?  My goal is to have the hyperlink change the contents of a cell upon being clicked.
Question by:shiny
    LVL 33

    Expert Comment

    //try this simple example by Antithesis. The key here is the getElementById function.
    //Once you give each cell an id you could reference it in whatev'r way you want
    <script language="javascript">
    function getobj(g_elm)  {
        if (document.all) return document.all[g_elm];
        if (document.layers) return document.layers[g_elm];
        if (!document.all && document.getElementById) return document.getElementById(g_elm);
    function chng(c_el, c_tx)  {
        getobj(c_el).innerHTML = c_tx;
    <table name="myTable" border="1">
    <tr name="TheRow">
      <td id="TheCell">My cool text</td>
      <td>Another Text</td>

    <a href="javascript:chng('TheCell', 'New text')">change</a>
    LVL 53

    Accepted Solution

    Three options:

    1.  If you just want to target teh cell to insert some text or an image then you bring them in with the original page in a hidden layer and then then swap the nodes from the onclick event of the link.  Using the onclick event means Jaascript must be enable.

    2.  Use XMLHTTP with a lot of scripting.  This will equire not just JavaScript support, but for IE will also requie active x support.

    3.  Put an iframe in the cell and target that.  Pure HTML.

    3 is my preferred option and would work like this:

    <td><iframe name="targetF" src=""></iframe></td>

    The link would look like:
    <a href="blah.html" target="targetF">click for blah</a>


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    "I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now