Get all elements in firefox

S

Sunny

Does anyone knows, how to all the list of all the elements on the web
page using javascript.
 
M

Martin Honnen

Sunny said:
Does anyone knows, how to all the list of all the elements on the web
page using javascript.

document.getElementsByTagName('*')
should give all elements in the document. Assuming "web page" is an HTML
document and you want the elements in the body then you might only want
to look in the body e.g.
document.body.getElementsByTagName('*')
 
S

Sunny

document.getElementsByTagName('*')
should give all elements in the document. Assuming "web page" is an HTML
document and you want the elements in the body then you might only want
to look in the body e.g.
document.body.getElementsByTagName('*')

When I do:
alert(document.getElementsByTagName('*'));
It gives me "Object HTML Collection"
I want to see, all the elements name in my web page.
As I am creating some elements dynamically, i want the name of all the
elements present on my webpage.
And I want to do that in Firefox.
Any solution.
 
J

Joost Diepenmaat

Sunny said:
When I do:
alert(document.getElementsByTagName('*'));
It gives me "Object HTML Collection"
I want to see, all the elements name in my web page.

Well, yeah.

var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length; i++) {
alert(elements);
}

Though I would strongly recommend you install firebug, enable it and do:
console.debug(elements);

then check the console.
 
S

SAM

Le 10/3/08 7:09 PM, Sunny a écrit :
When I do:
alert(document.getElementsByTagName('*'));
It gives me "Object HTML Collection"

Yes, that is a collection.
I want to see, all the elements name in my web page.

What do you call "name" ?
The name, the id, the tag name ?

var c = [];
var d = document.getElementsByTagName('*');
for(var i=0, n = d.length; i<n; i++) c.push(d.tag+Name);
alert(c.join());

but that will not give you the hierarchy
(nor wich ones are imbricated nor in what)
As I am creating some elements dynamically, i want the name of all the
elements present on my webpage.
And I want to do that in Firefox.
Any solution.

use the extension 'FireBug'
 
E

Eric B. Bednarz

Sunny said:
When I do:
alert(document.getElementsByTagName('*'));
It gives me "Object HTML Collection"
I want to see, all the elements name in my web page.
As I am creating some elements dynamically, i want the name of all the
elements present on my webpage.
And I want to do that in Firefox.

As you might have gathered from previous replies, you
a) need to do something with the collection
b) it isn’t clear from your description what that would be

If you just want a list of the used element types, you’d want to
avoid duplicates and probably sort the result, e.g.

var list = document.getElementsByTagName('*'),
l = list.length,
result = [],
node;
while (l--) {
node = list[l].nodeName;
if (-1 === result.indexOf(node)) {
result.push(node);
}
}
alert(result.sort());

(Joost’s suggestion applies)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top