Skip to Content

Stylegala Forums » Forums list » Problem solving

open a div on click

open a div on click

Goto page 1, 2  Nextpost new topic Post new topic    Reply to topic Reply to topic

Author Message
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Tue Nov 15, 2005 23:24
Hope the title explains the basics ! I want to open/show a layer/div with a click on a link. Is this possible, looked at open browser window but looks a bit chunky. Amateur at the web so I may be asking the obvious !

regards

gordonw

View user's profile Send private message
 
Sponsor
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Tue Nov 15, 2005 23:32
Not sure these are best ways... just a couple that I know of.
http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm
- and -
http://moofx.mad4milk.net/tests.html
Click on toggle height or toggle width, repeated clicking opens then closes the div, these are cool and maybe more advanced.
Both of these use javascript, maybe there's a way to do it without the jS?

Here's another from Apple: http://developer.apple.com/internet/webcontent/hideshow_layer.html
Towards the bottom of the page there's links to some examples... these look to be similar to what some would call a tooltip popup... you'ld also find examples of these at dynamic drive.

View user's profile Send private message
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Wed Nov 16, 2005 09:49

/*I fashioned this show hide function with help from www.quirksmode.com */
function toggle(id){ 
   if(document.getElementById){
       layer = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
       document.getElementById(id).style.display = layer;
   }
}


down and dirty works.. man TzMedia he said he was a noob, and you sent him to links that intermediate and advanced folks would rub thier forheads at :) not the mooFX link thats a pretty straight forward one. but dynamicdrive??/ lol Iused to usethem a while ago, that link brought back old memories.

anyway you could use this attached in an external js document or writte onthe page and call it by onclick="toggle('yourIDname');"

View user's profile Send private message
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Wed Nov 16, 2005 17:19
Here is what I am using:


function toggle(id){
if (document.getElementById){
var el = document.getElementById(id);
el.style.display = (el.style.display == 'none') ? 'block' : 'none';
}
}


And if you want the div to be hidden by default just add this to the Javascript:


window.onload = function(){
toggle('your-div-id-here');
}


Of course you would change 'your-div-id-here' to the id of the div you want to hide.

And here is what you put in your HTML:


<a href="#" onclick="toggle('your-div-id-here')" title="A title if you want or need one">Link01</a>


or


<a href="javascript:toggle('your-div-id-here')" title="A title if you want or need one">Link01</a>


and you could always add more divs that do the same thing just by calling the toggle with a different id.

View user's profile Send private message
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Sun Nov 20, 2005 16:31
Thanks for the help gents - eventually went with Joshua Kendalls, after my son explained how it worked !

Regards

gordonw

View user's profile Send private message
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Sun Nov 20, 2005 16:41
Have you got a link to see it in action ... that'ld be great?
Thanks... glad you found something then.

View user's profile Send private message
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Sun Nov 20, 2005 23:35
hmmmmmm. what was the difference between what Kendall gave you and what I gave you?

View user's profile Send private message
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Mon Nov 21, 2005 00:52
hmmmmmm. what was the difference between what Kendall gave you and what I gave you?


You tell me, all was most appreciated, take note from my initial question 'amateur' and my first thanks 'after my son explained how it worked !'

again thanks for the help...

regards

gordonw

View user's profile Send private message
 
clemi

  • Joined: 01 Mar 2005
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Mon Nov 21, 2005 09:38
climaxdesigns wrote:
hmmmmmm. what was the difference between what Kendall gave you and what I gave you?

They do the same thing, but Joshua's use of a 'ternary conditional' is simply a more efficient way of peforming the check and returning the appropriate output.

View user's profile Send private message Visit poster's website
 
Lost_User

  • Joined: 22 Jun 2006
  • Posts: 0
  • Status: Offline
Reply with quote Post Posted: Mon Nov 21, 2005 23:49
Bill

You about 30 with a degree in computer science, sound very like my son! I do this for fun ! Ternary sounds like some medical condition :-)

gordonw

View user's profile Send private message
 

Goto page 1, 2  NextPage 1 of 2

post new topic Post new topic    Reply to topic Reply to topic

Display posts from previous:   

Powered by phpBB. © 2001, 2006 phpBB Group & Logo Design