Click to See Complete Forum and Search --> : displaying elements


Sam
04-28-2004, 04:32 PM
I've got a definition list dynamically generated by php of varying lengths. It is the only definition list on the page. What is the best way to hide all of the element's except one? I know that i could use getElementsByTagName, but how would i refrence their styles (assuming they don't have an inline style attribute?) I suppose I could add an inline style attribute, but it seems like there should be another way around this issue.

David Harrison
04-28-2004, 05:48 PM
What's wrong with just this:



var donthide=7;

for(var n=0;n<document.getElementsByTagName("dt").length;n++){

if(n!=donthide){
document.getElementsByTagName("dt")[n].style.display="none";
document.getElementsByTagName("dd")[n].style.display="none";
}

}

Sam
04-28-2004, 05:54 PM
I thought that .style won't work unless you have a style attribute in your markup?

David Harrison
04-28-2004, 05:59 PM
You can set the styles for elements quite easily but you can't retrieve the styles that aren't set inline with the element (at least not that I know of).

fredmv
04-28-2004, 06:16 PM
Originally posted by lavalamp
you can't retrieve the styles that aren't set inline with the elementYou can, with a little help from DOM2 CSS. See this thread (http://forums.webdeveloper.com/showthread.php?s=&threadid=25930) for more details.

David Harrison
04-28-2004, 06:33 PM
Is there some sort of online reference for all of the DOM stuff that's even remotely user friendly. All I can find is just lists of things that when I try and read them I just end up staring into space.

Like the W3C site for instance, it's just very large blocks of text that I have to really concentrate and force myself to try and read.

fredmv
04-28-2004, 06:34 PM
The Mozilla Gecko DOM reference (http://www.mozilla.org/docs/dom/domref/) would be a good start.

David Harrison
04-28-2004, 06:44 PM
That looks pretty good, I'll check it out in detail at school tomorrow (today).

Sam
04-28-2004, 06:52 PM
alright, I've got it up in a script, and it is working onload, but not on the links. The script is here: http://www.samingle.com/album.js
and the page it's on is here:
http://www.samingle.com/showpics2.php?dir=/don/Radiohead_Trip/
I'd imagine it has something to do with the links being dynamically generated via the setupLinks() function (which i chose to put there since the links would just be confusing for those without js)

David Harrison
04-28-2004, 07:23 PM
I know that this isn't the DOM way to do things, but remember I haven't gone through that list yet Fred. ;)

Why don't you just document.write the links right into your page? You know how many items you have in your definition list because you can count them as you write them with the server-side coding, then put that number into the JavaScript code.

Sam
04-30-2004, 04:25 PM
Got it working now, the problem wasn't with the dynamically generated links, but rather that I didn't have anything I didn't have anything resetting the display back to block. Looks like its up and running now.