By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 3,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

Get all elements in firefox

P: n/a
Does anyone knows, how to all the list of all the elements on the web
page using javascript.
Oct 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Sunny wrote:
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('*')

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 3 '08 #2

P: n/a
On Oct 3, 12:58 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Sunny wrote:
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('*')

--

Martin Honnen
http://JavaScript.FAQTs.com/
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.
Oct 3 '08 #3

P: n/a
Sunny <su**********@gmail.comwrites:
On Oct 3, 12:58 pm, Martin Honnen <mahotr...@yahoo.dewrote:
>Sunny wrote:
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('*')

--

Martin Honnen
http://JavaScript.FAQTs.com/

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[i]);
}

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

then check the console.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Oct 3 '08 #4

P: n/a
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[i].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'

--
sm
Oct 3 '08 #5

P: n/a
Sunny <su**********@gmail.comwrites:
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)
--
||| hexadecimal EBB
o-o decimal 3771
--oOo--( )--oOo-- octal 7273
205 goodbye binary 111010111011
Oct 3 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.