Tag item

31 views
Skip to first unread message

sailor

unread,
Feb 12, 2012, 3:36:42 PM2/12/12
to Firebug
hello....

if i have page include 100 div tag

<div> somthing 1 </div>
<div> somthing 2 </div>
<div> somthing 3 </div>
<div> somthing 4 </div>
<div> ................ </div>
<div> somthing 100 </div>

how i can use firebug to identify div number to put it in
document.getElementsByTagName('div')[ ....here....];

Jan Honza Odvarko

unread,
Feb 13, 2012, 2:41:54 AM2/13/12
to fir...@googlegroups.com
I am not sure if I understand the question, but you can use the HTML panel and Firebug Inspector to see the inner text (in an individual DIV element) and also see the index number, no?

Honza

Sebo

unread,
Feb 13, 2012, 5:19:44 AM2/13/12
to fir...@googlegroups.com
Also you can right-click on the <div> inside the HTML panel and copy the XPath to the clipboard via Copy XPath. When you paste it to an editor, you will see the index of the node.
Also after inspecting an element you can refer to the inspected element inside the Command Line via $0.

Sebastian

sailor

unread,
Feb 13, 2012, 6:40:35 AM2/13/12
to Firebug
On Feb 13, 1:19 pm, Sebo <sebastianzart...@gmx.de> wrote:
> Also you can right-click on the <div> inside the *HTML* panel<http://getfirebug.com/wiki/index.php/HTML_Panel>and copy the XPath to the clipboard via
> *Copy XPath*. When you paste it to an editor, you will see the index of the
> node.
> Also after inspecting an element<http://getfirebug.com/wiki/index.php/Inspector>you can refer to the inspected element inside the Command
> Line <http://getfirebug.com/wiki/index.php/Command_Line> via $0.
>
> Sebastian

======================

Hello...

Thank you Honza & Sebastian for helping me..

Sorry for my language, but i mean that if a page include many div tags
( for example : 100 div tags) , when I get one of the div tags after
inspecting ,how i can know this div tag number, is it div number 1 or
div number 50 on the , grounds that we sequentially from the beginning
of page.

thanks.....

======================




Sebo

unread,
Feb 13, 2012, 6:51:44 AM2/13/12
to fir...@googlegroups.com
when I get one of the div tags after inspecting ,how i can know this div tag number
Sounds like you didn't try my hint with the XPath. There you will see something like /html/body/div[10], where 10 is the index of the element relative to its parent.

Sebastian

Jan Honza Odvarko

unread,
Feb 13, 2012, 6:54:01 AM2/13/12
to fir...@googlegroups.com
If you want to get the index programmatically you can use jQuery (or see how it's implemented)

Example:
$(".netRow").click(function () {
console.log( $(this).index() );
});
$("div").click(function () {
    console.log( $(this).index() );
});

More info:
http://stackoverflow.com/questions/4996002/jquery-get-index-of-element-as-child-relative-to-parent

Honza
$(".netRow").click(function () {
console.log( $(this).index() );
});
$(".netRow").click(function () {
console.log( $(this).index() );
});
 

sailor

unread,
Feb 13, 2012, 7:14:58 AM2/13/12
to Firebug
Thank you Sebastian...

i did your hint on google main page "http://www.google.com"
i inspected google logo and i got xpath : /html/body/div[2]/center/
span/center/div/div/div/

the last div tag without number , how i can know its div number 23
because i used traditional way by counting the div tags from the start
but i want it by firebug fast ...

Thanks...

Sebo

unread,
Feb 13, 2012, 8:16:43 AM2/13/12
to fir...@googlegroups.com
I guess the question is for what you need to know, that it's the 23rd <div>. HTML builds a tree structure, so normally a developer would want the index related to the parent node and not to the very first node.
And in the case of the logo of google.com I would simply access it via it's id: document.getElementById("lga").
If you really need the index, then you should use a JavaScript Framework as Honza explained it in regard of jQuery.

Sebastian
Reply all
Reply to author
Forward
0 new messages