Hi
Javascript newbie here – I know my way around a bit of serverside and SQL stuff but client side still eludes me slightly.
On a page, I have several div tags with incrementally numbered id attributes:
[code]
<div id=”content[1]”>blah blah</div>
<div id=”content[2]”>yada yada</div>
<div id=”content[3]”>rhubarb rhubarb</div>
What I need is a function that can count the number of ‘content’ div tags – i.e. how large the content array is.
I’ve taken a pre-written script and jigged with it so it does what I need but currently I need to manually update a variable holding how many content div tags there are which is an ugly solution.
Can anyone help me out please? ? Thanks in advance!
P.S. This is my script as it currently stands. Any advice is welcomed ?:
[code]
function DS_switchto(id)
{
var numberofpages=2;
if (document.all)
{
for (z = 1; z <= numberofpages; z++)
{
document.all[‘content[‘+z+’]’].style.display = ‘none’;
}
document.all[‘content[‘+id+’]’].style.display = ”;
return false;
} else if (document.getElementById)
{
for (z = 1; z <= numberofpages; z++)
{
document.getElementById[‘content[‘+z+’]’].style.display = ‘none’;
}
document.getElementById(‘content[‘+id+’]’).style.display = ‘block’;
return false;
}
}