3 replies [Last post]
Napper
Offline
newbie
Last seen: 15 years 24 weeks ago
Joined: 2004-06-06
Posts: 7
Points: 0

Hi everybody,

this is in regard to the tutorial Tony has set up (http://www.csscreator.com/css-forum/ftopic526.html). I have a similar "hiding things" script on my webpage and it is working out alright, except for one little annoyance that is driving my up randon walls. At the beginning of every page load you will have to click two times on the link instead of one. Explain this to a customer...

-"So I have to press on this?"
-"Yes - twice."
-"Okay - twice"
-"Yeah - but only the first time."
-"What?"
-"When you open it, you press it twice, after that only once."
-"Okay - to open press twice, to close once; Got it."
-"No - only for the first time you open it. After that you only once. Until you reload..."
-"I think I'm confused..."

Aaaaanyway - so I plugged Tonies script into the web-page and it did the same thing, so I am wondering where the fault might lie. I've set up a testing page:

http://www.kiebitzberg.de/test5.htm

to illustrate the problem. This is tested on Opera, Firefox and Mozilla.

Any hints are very much appreaciated.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 days 13 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

"Hiding Things" - Reloaded

Hi Napper,
It's to do with the first testing of the value of display.
If you test to see if the object is not hidden instead of hidden it should work on first click.
obj.style.display=(obj.style.display!='none') ? 'none' :' inline' ;

Hope that helps

Napper
Offline
newbie
Last seen: 15 years 24 weeks ago
Joined: 2004-06-06
Posts: 7
Points: 0

"Hiding Things" - Reloaded

Perfect!!!! That was it! And I've been spending days trying to find a solution for this on the web... Smile

Thanks, Tony!

Napper

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 4 years 45 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

"Hiding Things" - Reloaded

Napper, just as a point of reference you may want to check the html as you have a block level element nesting within an inline one which won't please the validator Wink

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me