Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-16-2009, 08:52 AM   PM User | #1
111buddy11
New to the CF scene

 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
111buddy11 is an unknown quantity at this point
Hide div onload, show onclick?

Hi all,

I apologise for asking this question, have searched for and found several thread solving this question however I can never get the solutions given to work, I have no idea what I'm doing wrong.. could it possibly have something to do with using prototype/scriptaculous at the same time??

current classes that effect this problem in css file:
Code:
.hidden{
	display:none;	
}

.shown{
}
Code:
<div id="splashtext">
<a href="#none" onclick="$('bodytext').fade();$('portfolio').appear({delay: 0.8});$('contact').fade();$('about').fade(); return false;">portfolio</a>
</div>

<div id="portfolio" class="hidden">
portfolio text
</div>
when portfolio is clicked, I need the portfolio div to change to
<div id="portfolio" class="shown"> ..... is this possible?

Last edited by 111buddy11; 03-16-2009 at 09:19 AM..
111buddy11 is offline   Reply With Quote
Old 03-16-2009, 09:05 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Code:
<div id="portfolio" class="hidden">
portfolio text
</div>
Quote:
when portfolio is clicked, I need the portfolio div to change to
<div id="portfolio" class="hidden">
Sorry, your intention is not clear.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 03-16-2009, 09:20 AM   PM User | #3
111buddy11
New to the CF scene

 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
111buddy11 is an unknown quantity at this point
apologies, have edited original post.

should have in fact been
Quote:
when portfolio is clicked, I need the portfolio div to change to
<div id="portfolio" class="shown">
111buddy11 is offline   Reply With Quote
Old 03-16-2009, 09:31 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
I don't know if this is what you want - toggle visibility.

Code:
<a href="#" onclick = "toggle()">Show or hide the portfolio</a>
<div id="portfolio" class = "hidden" style="display:none">
Portfolio text - but don't display me yet
</div>

<script type = "text/javascript">

function toggle(){
var divn1 = document.getElementById("portfolio");
if (divn1.style.display == "none") {
divn1.style.display = "block";
}
else {
divn1.style.display = "none";
}
}

</script>

I heard him then, for I had just
Completed my design
To keep the Menai Bridge from rust
By boiling it in wine.
- Lewis Carroll
Philip M is offline   Reply With Quote
Old 03-16-2009, 09:34 AM   PM User | #5
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Code:
<script type="text/javascript">
window.onload=function(){
var elm= document.getElementById('portfolio');
elm.className='shown';
}
</script>
You might need to adjust the above in such way a that it won't interfere with other onload even handlers, if any.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 03-16-2009, 10:43 AM   PM User | #6
111buddy11
New to the CF scene

 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
111buddy11 is an unknown quantity at this point
Philip M, when I tried your solution, it simply showed "show or hide the portfolio"... when it was clicked that text disappeared.... "Portfolio text - but don't display me yet" never showed up


abduraooft
, so i place
Code:
<script type="text/javascript">
window.onload=function(){
var elm= document.getElementById('portfolio');
elm.className='shown';
}
</script>
in the head? what do i add to the onlick part of the link?




not sure wether this will help but this is the page where the about, portfolio and contact divs are hidden.. I need them to be shown when the appropriate link is clicked on the right



.... and here is the mess i am trying to fix by initially having those divs hidden

Last edited by 111buddy11; 03-16-2009 at 10:46 AM..
111buddy11 is offline   Reply With Quote
Old 03-16-2009, 12:09 PM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by 111buddy11 View Post
Philip M, when I tried your solution, it simply showed "show or hide the portfolio"... when it was clicked that text disappeared.... "Portfolio text - but don't display me yet" never showed up
[I]
Well, it works just fine for me.

Is it that the class = "hidden" is affecting it?

Last edited by Philip M; 03-16-2009 at 12:17 PM..
Philip M is offline   Reply With Quote
Old 03-17-2009, 09:53 AM   PM User | #8
111buddy11
New to the CF scene

 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
111buddy11 is an unknown quantity at this point
sorry yes my apologies, it does work.. However I can only get it working on a page by itself

How do I add the toggle() to the portfolio tag along with what is already there?

I have tried this but it doesnt seem to work?
Code:
<a href="#" onclick="$('bodytext').fade();$('portfolio').appear({delay: 0.8});$('contact').fade();$('about').fade(); return false;toggle()">portfolio</a><br />
111buddy11 is offline   Reply With Quote
Old 03-17-2009, 10:01 AM   PM User | #9
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
You need to add it before return false;
Code:
<a href="#" onclick="$('bodytext').fade();$('portfolio').appear({delay: 0.8});$('contact').fade();$('about').fade(); toggle(); return false;">portfolio</a><br />
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 03-18-2009, 09:51 PM   PM User | #10
111buddy11
New to the CF scene

 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
111buddy11 is an unknown quantity at this point
I'm not sure why this is happening, as this works fine on its own:
Code:
<a href="#" onclick = "toggle()">Show or hide the portfolio</a>
<div id="portfolio" class = "hidden" style="display:none">
Portfolio text - but don't display me yet
</div>

<script type = "text/javascript">

function toggle(){
var divn1 = document.getElementById("portfolio");
if (divn1.style.display == "none") {
divn1.style.display = "block";
}
else {
divn1.style.display = "none";
}
}

</script>
however when I try to add it into the content already shown, the text "Show or hide the portfolio" is the only thing that disappears when it is clicked?

shown here ("Show or hide the portfolio" is located at the top of the text thats shown on page load)

Last edited by 111buddy11; 03-18-2009 at 10:01 PM..
111buddy11 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 AM.


Advertisement
Log in to turn off these ads.