Results 1 to 8 of 8

Thread: document.innerHTML

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Posts
    23

    Angry document.innerHTML

    Hi

    I am trying to create a javascript that will tell me all the "ID"s associated with the HTML tags as I can change them later by getElementById() method

    for example

    instead of writing

    document.getElementById("myid").innerHTML = "<b>Hello World</b>"

    I want to write

    var var_myID

    var_myID = Some code that can dinamically find any "ID" associated with any TAG

    document.getElementById(var_myID).innerHTML = "<b>Hello World</b>"

    can any one suggest me any idea

    kajol

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: document.innerHTML

    I absolutely don't get what you want.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: document.innerHTML

    I think she wants to get the ElementID of an element whose ID she's going to change, after it has changed.

    Careful... a wormhole might open into another dimension.

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    Re: document.innerHTML

    I think what you want is looping through all the tags in a page and extract the ID's from those which have one, and then use that ID to change the innerHTML?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Posts
    23

    Re: document.innerHTML

    Hi Jop

    this is what I want to do
    do you have any solution

    kajol

    Quote Originally Posted by Jop
    I think what you want is looping through all the tags in a page and extract the ID's from those which have one, and then use that ID to change the innerHTML?

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: document.innerHTML

    But what sense does that make?

    I mean, you can use various ways of getting all elements (simplest is document.getElementsByTagName('*')), and the loop through them and look where the id attribute is not empty, but...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Posts
    23

    Re: document.innerHTML

    Thanks

    I did it with the following code

    a = document.all
    for( i = 0 ; i < a.length ; i ++ )
    {
    e = document.getElementsByTagName(a[i].tagName)
    for( j = 0 ; j < e.length ; j ++ )
    {
    if(e[j].id != "")
    {
    ...
    ...
    }
    }
    }

    kajol

    Quote Originally Posted by CornedBee
    But what sense does that make?

    I mean, you can use various ways of getting all elements (simplest is document.getElementsByTagName('*')), and the loop through them and look where the id attribute is not empty, but...

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: document.innerHTML

    Whoa, this inner loop runs, well, hard to calculate, but FAR more often than it needs to. And you artificially made it IE-only.
    Code:
    e = document.getElementsByTagName('*')
    for( j = 0 ; j < e.length ; j ++ )
    {
      if(e[j].id != "")
      {
        ...
        ...
      }
    }
    This suffices completely.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width