Is there a faster way to change span innerHTML

Discussion in 'Javascript' started by Charlie T, Nov 11, 2004.

  1. Charlie T

    Charlie T Guest

    Here is the code I am currently using.... can anyone think of a speeder process?

    -------
    function changeDiv(tagID, tagData) {
    if(document.getElementsByTagName) {
    var divs = document.getElementsByTagName('span');
    for(var i = 0, n = divs.length; i < n; ++i) {
    if(tagID == divs.id) {
    divs.innerHTML = tagData;
    }
    }
    }
    }
    -------
     
    Charlie T, Nov 11, 2004
    #1
    1. Advertising

  2. Charlie T wrote:

    > Here is the code I am currently using.... can anyone think of a speeder process?
    >
    > -------
    > function changeDiv(tagID, tagData) {
    > if(document.getElementsByTagName) {
    > var divs = document.getElementsByTagName('span');
    > for(var i = 0, n = divs.length; i < n; ++i) {
    > if(tagID == divs.id) {
    > divs.innerHTML = tagData;


    Well if you have unique id values (as you should have) you can just access
    document.getElementById(tagID).innerHTML = tagData

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 11, 2004
    #2
    1. Advertising

  3. On Thu, 11 Nov 2004 18:57:58 +0100, Martin Honnen <>
    wrote:

    [snip]

    >> function changeDiv(tagID, tagData) {
    >> if(document.getElementsByTagName) {
    >> var divs = document.getElementsByTagName('span');
    >> for(var i = 0, n = divs.length; i < n; ++i) {
    >> if(tagID == divs.id) {
    >> divs.innerHTML = tagData;

    >
    > Well if you have unique id values (as you should have) you can just
    > access
    > document.getElementById(tagID).innerHTML = tagData


    This is from a thread in September
    (<URL:http://groups.google.com/groups?threadm=ee9445b6.0409071820.299b03d7%40posting.google.com>).
    The code above is based on my suggestion, but I was using classes, not ids.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Nov 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fulio Open

    Can span include span?

    Fulio Open, Jun 26, 2009, in forum: HTML
    Replies:
    5
    Views:
    576
    dorayme
    Jun 26, 2009
  2. Stéphane Klein
    Replies:
    2
    Views:
    1,859
    John Nagle
    Mar 30, 2010
  3. Stefan Behnel
    Replies:
    0
    Views:
    504
    Stefan Behnel
    Mar 29, 2010
  4. Dan Bishop

    DataGrid (body only) contained in <span>...</span> tags

    Dan Bishop, Jun 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    306
    Kilic Beg
    Jun 7, 2004
  5. sonic
    Replies:
    5
    Views:
    310
    Randy Webb
    Jul 11, 2006
Loading...

Share This Page