[Javascript] See if item is hidden...
Paul Novitski
paul at novitskisoftware.com
Tue Jun 22 16:01:56 CDT 2004
At 01:33 PM 6/22/2004, jsWalter wrote:
>1) I really won't know how far down my Pa21 might be.
> (Yes, another of Walters "generic" code pieces)
>
>2) its ancestor would be turned off by JS via a code switch
> but then again, its default state (via CSS) could have it "off"
1) It's easy to walk up the DOM tree looking for a parent, as long as you
know when you've found it. You could look for a tag name or, better yet,
an id or classname (so you can mess with your tags later on and not have it
break).
I'll assume that your function is triggered from within the span:
<div class="Grandma">
<p>
<!-- any number of levels here -->
<span onclick="DoSomething(this)">...
function DoSomething(argItem)
{
// begin with the chosen item
oObj = argItem
// look for the desired ancestor
while (oObj.className != "Grandma")
{
// walk up one level
oObj = oObj.parentElement
}
// check visibility by whatever method you like
if (oObj.style.visibility != "hidden") ...
if (oObj.style.display != "none") ...
if (oObj.className != "cssHiddenThing") ...
}
As I understand it, testing the value of oObj.style.whatever will test for
attributes applied with either HTML or JavaScript:
<div style="whatever: itis;">
or:
oObj.style.whatever = "itis"
but will not detect attributes applied with CSS:
div {whatever: itis;}
In order to do that, you'd need to parse the stylesheet tree, discover
which CSS selectors applied to your object, follow all the rules of
cascading, etc.
It would be much easier simply to load up your page KNOWING how things are,
set them differently if desired with Javascript, and work from there.
Paul
More information about the Javascript
mailing list