473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1403
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
11
by: z_learning_tester | last post by:
Hello, yes another beginner question that I'm sure is obvious to many here :-) My book is so bad. Really. It uses the exact same example of code for using the new kw and for using virtual(in the...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
15
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
14
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to...
9
by: chikkubhai | last post by:
Why is the result different for the following set of two code snippets Code without using this pointer #include <string> #include <iostream> using namespace std; struct X { private:
7
by: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post by:
Hi, I have been using the code (some of it has been removed for simplicity) below to allow authenticated (using ASP.NET membership database) users to get a file from their archive area. It...
0
by: Joe Strout | last post by:
Hi Luis, A static variable IS encapsulation. Encapsulation happens at many levels: module, class, instance, and (in languages that support it) method. A static local variable is simply the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.