/    Sign up×
Community /Pin to ProfileBookmark

Javascript for a nav area with no page reload

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>
[/CODE]

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>
[/code]

And the anchors to click on look like this:

[code]
<a target=”_self” onClick=”ChangeElementsByName(‘name1’);”>CLICK ME</a>
[/code]

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? ^_^

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManSep 29.2007 — id help, but your description is throwing me way off. i think i understand:

a nav area with a series of tabs[/quote]

i picture:

<i>
</i>[TAB][TAB][TAB][TAB]
----------------------------------------
| |
| CONTENT AREA |
| |
----------------------------------------


but:

I want those tabs to display one specific of a series of tabs[/quote]

doesnt make sense. it sounds like each tab will have a bunch of other tabs (so if i have 4 "parent" tabs, each "parent" has four "child" tabs, which means there are 16 tabs in total. that seems terribly excessive.

and then you say:

you can click on the tab and it will pull up a list of links associated with that particular tab.[/quote]

so that means there are 4 parent tabs, X number of child tabs per parent tab, and then a list of links for each child tab...?

and then this serves to only completely cloud the situation:

The number of tabs and divs will be 1:1[/quote]

i get completely, completely lost here. it stops making any sense to me any further.

clarification is needed.
×

Success!

Help @WiglyWorm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...