Keep in mind, I’m a pretty big newbie to javascript.
I have this piece of script to let me hide and show divs:
[CODE]
<script>
function TestElement(item)
{
if(item.className == “class1”)
item.className = “class2”;
else if(item.className == “class2”)
item.className = “class1”;
}
function ChangeElementsByName(name_check)
{
if(document.all) //IE
{
var objects = document.all;
var count = objects.length;
var i = 0;
for(i = 0; i < count; ++i)
{
var object = objects.item(i);
if(object.name == name_check)
TestElement(object);
}
}
else //mozilla
{
var objects = document.getElementsByName(name_check);
var count = objects.length;
var i = 0;
for(i = 0; i < count; ++i)
{
var object = objects.item(i);
TestElement(object);
}
}
}
</script>
It works for its intended purpose, but I have a new thing I’m working on which needs a little bit more detail.
I’m making a nav area with a series of tabs, and I want those tabs to display one specific of a series of tabs, and hide all others, this way you can click on the tab and it will pull up a list of links associated with that particular tab.
The number of tabs and divs will be 1:1, but I’ll need to be able to expand it easily, preferably without having to rewrite the java (since I’m new at this and don’t want to spend hours figuring out what to do each time).
The HTML would look (basically) something like this:
[code]
<div name=”name1″ class=”class1″> HIYA </div>
<div name=”name1″ class=”class2″> HIYA 2</div>
<div name=”name1″ class=”class3″> HIYA 3</div>
<div name=”name1″ class=”class4″> HIYA 4</div>
And the anchors to click on look like this:
[code]
<a target=”_self” onClick=”ChangeElementsByName(‘name1’);”>CLICK ME</a>
Of course, all three of these will likely need tweaked.. can someone point me to some examples or get me moving in the right direction, please?
I guess what I’m looking to do is, each time I click an anchor, make the all the elements with name=”name1″ be hidden, and then call one specific class and make that one visible.
Cant his be done? ^_^