User Name
Password
AppleNova Forums » Programmer's Nook »

Using focus() to hide div?


Register Members List Calendar Search FAQ Posting Guidelines
Using focus() to hide div?
Thread Tools
MagSafe
Senior Member
 
Join Date: Apr 2006
 
2007-10-31, 06:45

Hi again,

I have another query related to JavaScript

Basically I have a div that drops-down when the user clicks a button, it's originally set to "display: none;" so when the user clicks the button its then set to "display: block;", and vice versa.

What i'd like to do is make this similar to drop-down window's in applications, where if the window is shown and the user clicks somewhere else on the screen, the window is then hidden again.

Is there a way of doing this with JavaScript? I'm thinking of using focus() to set the div to "display: none;" again when the user clicks somewhere else on the screen, but i'm not sure on how to go about doing this!

Cheers for any help,

Steve.

Find me on Twitter: @StevenMcLintock
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2007-10-31, 07:00

You mean like using onFocus() and onBlur()?
  quote
MagSafe
Senior Member
 
Join Date: Apr 2006
 
2007-10-31, 07:51

Yeah, thats what I mean

Except the opposite if you know what I mean, so when it isn't focused it'll do something.

Thanks
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2007-10-31, 08:17

Can't you do something likeā€¦

<element onBlur="do-whatever-you-want">asdfsdfasdf</element>

Shouldn't that do whatever you do when you are no longer focused on an element?
  quote
MagSafe
Senior Member
 
Join Date: Apr 2006
 
2007-10-31, 08:37

Just tried that,

It doesn't seem to working, I checked on W3 Schools and the div object isn't supported unfortunately.

Thanks anyway though
  quote
Gargoyle
http://ga.rgoyle.com
 
Join Date: May 2004
Location: In your dock hiding behind your finder icon!
 
2007-10-31, 09:55

If the button that they click on is within the div that drops down, you could use onmouseout="".
  quote
MagSafe
Senior Member
 
Join Date: Apr 2006
 
2007-10-31, 11:46

I got it working ...eventually, it took about 2hr's but I finally worked it out

What I did was use the onclick event to see if the div was shown, if it was and the user wasn't clicking within the div, the div would be hidden.

If anyone wants the code, let me know

Thanks again,

Steve.

Find me on Twitter: @StevenMcLintock
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2007-10-31, 14:27

Ohhh, I get what you wanted to do now. For some reason I re-read your post at least 3 times and couldn't figure out exactly what you were trying to do, which is why I used the <element> because I didn't know what you were applying it to. Of course reading your original post now is pretty clear. Well anyways good job, sorry I would have helped if I wasn't retarded.
  quote
MagSafe
Senior Member
 
Join Date: Apr 2006
 
2007-10-31, 14:31

Quote:
Originally Posted by ast3r3x View Post
Ohhh, I get what you wanted to do now. For some reason I re-read your post at least 3 times and couldn't figure out exactly what you were trying to do, which is why I used the <element> because I didn't know what you were applying it to. Of course reading your original post now is pretty clear. Well anyways good job, sorry I would have helped if I wasn't retarded.
Yeah it's quite complicated to explain

Thanks for the help though, you at least pointed me in the right path
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Post Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
Collapsable menus (showing + hiding DIV layers) Is it 1981? Programmer's Nook 9 2007-05-22 15:32
CSS: DIV obscured by prior DIV drewprops Programmer's Nook 12 2005-12-29 17:59
Final Cut Express - How do I add a good Soft Focus? Gizzer Genius Bar 0 2005-11-28 08:03
Cant hide from dock! MDK Genius Bar 4 2005-11-03 02:13
Do you hide the Dock? BlueRabbit General Discussion 32 2005-04-10 12:47


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 02:31.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova