|
-
May 7th, 2004, 09:00 AM
#1
Thread Starter
Ex-Super Mod'rater
JavaScript/CSS: Changing the class of an id with a javascript.
I have a page and I want to be able to have a javascript on it that will let me change the class of a tag. For example:
Code:
<A HREF="Show(ItemA);">Show Item A.</A><BR />
<A HREF="Hide(ItemA);">Hide Item A.</A><BR />
<P id="ItemA" class="HiddenItem">This is Item A.</P>
So when Show() is ran the class of the ItemA should be changed to "" and when Hide() is ran it should chnage the class to "HiddenItem".
I have used to have some code that did this but I can't manage to find it . BTW I'm no good at Javascript as well .
Thanx
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
May 7th, 2004, 09:07 AM
#2
Frenzied Member
this is untested, but insert this into the hide function:
Code:
document.getElementById('ItemA').className = "HiddenItem"
and this into the show function:
Code:
document.getElementById('ItemA').className = ""
Have I helped you? Please Rate my posts. 
-
May 7th, 2004, 09:12 AM
#3
Thread Starter
Ex-Super Mod'rater
Thanx, that was along the lines of what I thought would be it. The function the last one used was quite long mind I think it didn't use classes though, it checked the visible and display settigns and just toggled them, but I think this will be better. I'll just test and see if it works....
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
May 7th, 2004, 09:20 AM
#4
Thread Starter
Ex-Super Mod'rater
Didn't seem to work, I don't know if I have done something else wrong though. Here is the Code I have used on the test page:
Code:
<HTML>
<HEAD>
<TITLE>Test Page</TITLE>
<LINK href="Electroman.css" type="text/css" rel="stylesheet">
<SCRIPT LANGUAGE="javascript">
function Show(IDName)
{
document.getElementById('ItemA').className = "Red";
}
function Show(IDName)
{
document.getElementById(IDName).className = "HiddenItems";
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript:Show('ItemA')">Show Item A.</A><BR />
<A HREF="javascript:Hide('ItemA')">Hide Item A.</A><BR />
<P id="ItemA" class="HiddenItems">This is Item A.</P>
</BODY>
</HTML>
CSS File:
Code:
.HiddenItems { VISIBILITY: Hidden; DISPLAY: none; }
The item is hidden to start with but nothing happens when I click the links
Last edited by Electroman; May 7th, 2004 at 09:24 AM.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
May 7th, 2004, 09:23 AM
#5
Thread Starter
Ex-Super Mod'rater
Nevermind, it works, its cos I had the two Show functions . It now works, Thanx.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|