Using class instead of ID with Div

M

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)
}
}
 
R

Randy Webb

(e-mail address removed) 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';
}
 
M

mrc

And now you no longer have any resemblance to valid HTML.

Exactly.
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
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top