SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    396
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Best way to do a basic hide/show script? (from a CSS perspective)

    At the moment I have some javascript that:

    - hides an element by setting it's position to absolute, and left to -9999em
    - shows an element by setting it's position to relative, and left to 0em
    - toggles by using a combination of the above in an if statement

    It mostly works fine, but whenever I try to show something that isn't a div (i.e. a list, or a table), in Internet Explorer a lot of stuff gets stuck off the screen for some reason.

    So, are there any more suitable alternatives?

    Thanks

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have you tried setting it to display:none?

  3. #3
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,343
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    So, are there any more suitable alternatives?
    There shouldn't be any problem in moving stuff off screen and back again so it would be better to find out why you are having those problems and then fix the issues. It should make no difference if its a div or a list. If you have an example of where it doesn't work we could try and offer a fix.

    The reason that moving elements off screen is better than using display:none is that the content becomes available to screen readers who may not read elements that have display:none.

    If it's not actual content then display:none is ok.

  4. #4
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    396
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Many thanks; nope I haven't tried display: none in this particular case but will see if it works anyway, although I didn't use it originally for the reasons that Paul mentioned.

    It's not content, but it is the sidebar navigation so still rather important

  5. #5
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    396
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Worked a treat, thank you! It's not ideal since like Paul said, the screenreaders won't be able to view it, but for this particular case (it's just to toggle navigation on certain pages; accessible from other pags anyway) it's great, cheers!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •