PDA

Click to See Complete Forum and Search --> : document.innerHTML


kajol
Dec 10th, 2004, 04:03 AM
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

CornedBee
Dec 10th, 2004, 09:47 AM
I absolutely don't get what you want.

mendhak
Dec 12th, 2004, 02:28 AM
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.

Jop
Dec 13th, 2004, 11:02 AM
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?

kajol
Dec 16th, 2004, 03:50 AM
Hi Jop

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

kajol

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?

CornedBee
Dec 16th, 2004, 04:57 AM
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...

kajol
Dec 17th, 2004, 01:01 AM
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

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...

CornedBee
Dec 17th, 2004, 06:05 AM
Whoa, this inner loop runs, well, hard to calculate, but FAR more often than it needs to. And you artificially made it IE-only.
e = document.getElementsByTagName('*')
for( j = 0 ; j < e.length ; j ++ )
{
if(e[j].id != "")
{
...
...
}
}

This suffices completely.