Old 20-12-2007, 12:26   #1 (permalink)
kwills
Now Freelance!
 
kwills's Avatar
 
Join Date: Aug 2006
Location: Warrington, UK
Posts: 476
Show/Hide Content

I am currently working on a site and would like to add a show/hide content link on a div so when it is clicked, the user can do either.

I have been looking at MooTools to do this but am not too sure about how to do it. I was just wondering if anyone could recommend the best way this could be done?
  Reply With Quote
Old 20-12-2007, 13:12   #2 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
make the html look like this:
Code:
<div id="targetDiv">Fill in your content here</div> <a href="javascript: show()">show</a> <a href="javascript: hide()">hide</a>

And make your javascript look like this:
Code:
<script language="javascript"> function show() { var targetDiv = document.getElementById("targetDiv"); targetDiv.style.display="block"; } function hide() { var targetDiv = document.getElementById("targetDiv"); targetDiv.style.display="none"; } </script>
  Reply With Quote
Old 20-12-2007, 13:30   #3 (permalink)
herkalees
Semantics, yay.
 
herkalees's Avatar
 
Join Date: Nov 2005
Location: Salem, Massachusetts
Posts: 1,128
Just remember that the language attribute has been deprecated. Use type instead:

<script type="text/javascript">
function show() {
var targetDiv = document.getElementById("targetDiv");
targetDiv.style.display="block";
}
function hide() {
var targetDiv = document.getElementById("targetDiv");
targetDiv.style.display="none";
}
</script>
__________________
  Reply With Quote
Old 20-12-2007, 13:45   #4 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 6,998
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Jquery!
__________________
  Reply With Quote
Old 20-12-2007, 18:04   #5 (permalink)
kwills
Now Freelance!
 
kwills's Avatar
 
Join Date: Aug 2006
Location: Warrington, UK
Posts: 476
Cheers guys, will have a look and let you know how i get on.
  Reply With Quote
Old 20-12-2007, 18:52   #6 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
Quote:
<script type="text/javascript">

Oops! By bad. I'm always trying to remember the right way to write that opening tag!
  Reply With Quote
Old 20-12-2007, 19:55   #7 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,695
I use mootools a fair bit. To be honest, it couldn't be much easier. They have online demos on their site of exactly what you want with the CSS and HTML. What are you having trouble with?
  Reply With Quote
Old 21-12-2007, 05:06   #8 (permalink)
kwills
Now Freelance!
 
kwills's Avatar
 
Join Date: Aug 2006
Location: Warrington, UK
Posts: 476
Quote:
Originally Posted by Hunch
I use mootools a fair bit. To be honest, it couldn't be much easier. They have online demos on their site of exactly what you want with the CSS and HTML. What are you having trouble with?

I have rarely used Javascript before when designing my sites and am not too sure how to implement it. I did have a look at MooTools but wasn't too sure how to use it.

I have been looking at this: jQuery Sliding Panels and wanted to use the box where you can toggle the show/hide content. I had a go at inserting it into a test page and couldn't seem to get it to work.

I could do with some help just implementing it into a blank document and looking how it functions. I didnt want to just put it into my site without knowing how it works.
  Reply With Quote
Old 21-12-2007, 07:50   #9 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
You should buy a book on javascript, or spend some time doing some tutorials then. Its not the easiest language, but it sure is functional! Its definitely worth learning.
  Reply With Quote
Old 21-12-2007, 08:45   #10 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,695
I think the main issue with javascript is understanding the DOM. I'd read up on that first and then a lot of the code you read will make more sense.
  Reply With Quote
Old 21-12-2007, 09:05   #11 (permalink)
kwills
Now Freelance!
 
kwills's Avatar
 
Join Date: Aug 2006
Location: Warrington, UK
Posts: 476
Cheers Guys, Im trying to learn PHP at the moment and am focusing on that, thought this would be ok just adding and know how to change/edit.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8