PDA

View Full Version : need help finding next element in DOM


o0O0o.o0O0o
02-12-2008, 02:27 AM
hi i have the list kike below


<UL id ='ul1'>

<LI id = 'li2' >

<a --->

<div id ='1'>Grocery
<a id = 'a3'class >Link

</a>

</div>

</a>

</li>


<UL id ='ul1'>

<LI id = 'li2' >

<a --->

<div id ='1'>Grocery-sub.
.
.
.
.
.


what i want is when i click on link a new text box appears after grocery
but i am not able to do it


i am able to get the reference of <li> but i am not able to get the reference of next <ul> element


i am using the following code



function setInsertable(id)


{

obj = document.getElementById(id);


a = obj.parentNode;

b = a.parentNode;

c = b.parentNode;


insertionPoint = c.lastChild;
v = insertionPoint.nextSibling
alert(v.id);

oesxyl
02-12-2008, 07:08 AM
you have same id for two ul:

<UL id ='ul1'>

<LI id = 'li2' >

<a --->

<div id ='1'>Grocery
<a id = 'a3'class >Link

</a>

</div>

</a>

</li>


<UL id ='ul1'>

<LI id = 'li2' >

<a --->

<div id ='1'>Grocery-sub.
.
.
.
.
.

best regards

o0O0o.o0O0o
02-12-2008, 07:14 AM
that was just example - - -

I want to know where i am wrong.

Is my logic correct , considering ids are different or anything else need to be done

one thing more when try this example IE and firefox give different results

looks like forefox is skipping anchor tag

How can i knoe that how firefox handles DOM elements , any links?/

Trinithis
02-12-2008, 07:27 AM
Siblings include TextNodes, and browsers handle them differently in some cases. If this is the issue, try something like:


v = insertionPoint.nextSibling;
while(v.nodeType == 3)
v = v.nextSibling;

oesxyl
02-12-2008, 07:28 AM
that was just example - - -

I want to know where i am wrong.

Is my logic correct , considering ids are different or anything else need to be done

one thing more when try this example IE and firefox give different results

looks like forefox is skipping anchor tag

How can i knoe that how firefox handles DOM elements , any links?/

I'm "learn in progress" with js, :)
this what I have closer to dom:

http://www.howtocreate.co.uk/tutorials/javascript/domevents

ffox use xul for interface.

http://www.xulplanet.com/

look to the xpcom reference

best regards