Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Changing cell contents on the fly...

    I am wondering if it is possible to change table contents dynamicall in Javascript. I know I can change background color and others, but can you change the entire contents and even the class? Take the following:

    Code:
    <table id="colors" name="colors">
    <tr>
    <td id="cellA" class="red">red</td>
    <td id="cellB" class="blue">blue</td>
    </tr>
    </table>
    Now I want to change the contents of cellA and class of cellA to green. Any ideas?

    Thanks in advance.
    Last edited by imanta; 04-12-2005 at 06:55 PM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Basic idea:

    var objElem = document.getElementById("theId");
    objElem.className = "newClass";
    objElem.innerHTML = "new text";

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Duh... innerHTML got it...

    How about changing an img src on the fly through JS? Any idea?

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    objElem.src = "blah.gif"
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •