469,336 Members | 5,240 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Using class instead of ID with Div

mrc
I have the following to show/hide Divs. This is fine, but I'm using
XSL to generate a page per person (for eample). As the div's are
declared statically when there is more than one person, the div id is
nolonger unique.

Would I be able to something similar to what is below using classes, or
will I have to dynamically create the div's giving them unique ID's

Many thanks

S

function hidediv(strdivname)
{
document.getElementById(strdivname).style.display= 'none'
}

function showdiv(strdivname)
{
document.getElementById(strdivname).style.display= 'block'
}

function togglediv(strdivname)
{
if (document.getElementById(strdivname).style.display == 'none')
{
showdiv(strdivname)
}
else
{
hidediv(strdivname)
}
}

Jun 5 '06 #1
3 1327
mr*@sean-connolly.co.uk said the following on 6/5/2006 11:22 AM:
I have the following to show/hide Divs. This is fine, but I'm using
XSL to generate a page per person (for eample). As the div's are
declared statically when there is more than one person, the div id is
nolonger unique.
And now you no longer have any resemblance to valid HTML.
Would I be able to something similar to what is below using classes, or
will I have to dynamically create the div's giving them unique ID's


You can do either. Although your functions are poorly written with the
way you have them set up.

function toggleDiv(strdivname){
el = document.getElementById(strdivname);
el.style.display = ('none' == el.style.display)? '' : 'none';
}

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 5 '06 #2
mrc
> And now you no longer have any resemblance to valid HTML.

Exactly.
Would I be able to something similar to what is below using classes, or
will I have to dynamically create the div's giving them unique ID's


You can do either. Although your functions are poorly written with the
way you have them set up.

function toggleDiv(strdivname){
el = document.getElementById(strdivname);
el.style.display = ('none' == el.style.display)? '' : 'none';
}


Yes that is much better than what I came up with, thankyou.

To use this with what I'm working with though, I'd have to dynamicaly
create the div ID's, how would I go about that then ?

e.g I'll need something like:

<div id="person1></div>
<div id="person2></div> etc etc

Many thanks

Sean

Jun 6 '06 #3
mrc
To use this with what I'm working with though, I'd have to dynamicaly
create the div ID's, how would I go about that then ?

e.g I'll need something like:

<div id="person1></div>
<div id="person2></div> etc etc

Figured this out:

Person{$posinloop}

where $posinloop == the position() in the xml document

Works a treat now, thanks!

S

Jun 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by z_learning_tester | last post: by
1 post views Thread by Anonieko | last post: by
7 posts views Thread by =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post: by
reply views Thread by Joe Strout | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.