Re: Get an element's ancestor node based on it's id?



getPanel=function()
{
var t=document.getElementById('li_id').parentNode;
while (!t.id && t!=document.body)
t=t.parentNode;
return t;

}

Sorry, allow me to clarify this code, I just re-read it and it's a
little ambiguous.

function closeDiv(div)
{
div.style.display='none';
}
getPanel=function(element)
{
var t=element.parentNode;
while (!t.id && t!=document.body)
t=t.parentNode;
return t;
}


and update your HTML to look like:

<div style="display: none;" id="panel1">
<div>
<a href="#" onclick="closeDiv(getPanel(this));return
false">Close</a>
</div>
</div>
.



Relevant Pages

  • Thumbnail Viewer adjusting
    ... here is simple and compact image viewer script, I'm satisfied with it, but ... as a thumbnail), resize it dynamically for thumbnail, so this did not ... //write out HTML for Image Thumbnail Viewer plus loading div ... var ie=document.all &&!window.opera ...
    (comp.lang.javascript)
  • Re: Help needed for a expand-collapse menu
    ... function getParentByTag(element, tag) { ... var div = getParentByTag; ... if (!div) return; // Fail silently ... so I need help with the collapse part and this is how I would like to ...
    (comp.lang.javascript)
  • RE: IE 7 Appears to Hang after JScript runs (code works in IE 5.5 & IE
    ... and all the JavaScript is in .js files. ... The div contains a list, user selects something and the onMouseUp event ... IE7 window or otherwise moves focus off, ... var iXOffset = oDivDdn.style.width; ...
    (microsoft.public.scripting.jscript)
  • Calculating the available screen height with which to work
    ... I have three main sections in the page: a mastehead, an iframe and a div. ... is just visible above the bottom of the screen. ... var availableHeight = body.clientHeight; ... The "-7" is the height (pixels) that the div etends below the bottom of the ...
    (microsoft.public.scripting.jscript)
  • Re: Test for existence of dynamic variable
    ... calling. ... I pass the function the ID of the div, and what I want in the ... var theTable; ... insertRow and insertCell. ...
    (comp.lang.javascript)