SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with a simple Toggle script

    I found a simple toggle script which opens and closes a div upon clicking the link. Is there a way for it to toggle without click the designated link.. or in other words, click anywhere on the page.


    function toggle_visibility(id) {
    var e = document.getElementById(id);
    if(e.style.display == 'block')
    e.style.display = 'none';
    else
    e.style.display = 'block';

    }
    onclick="toggle_visibility('idname');"
    Thank you!

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure on the 'usability' of such a thing, but if you're sure, just add the onclick event to the body tag rather than the link.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically I am using the function to toggle a sub-menu. So I made a menu. The issue is that Users don't want to click the link to close the menu. They just want to click anywhere to close the menu,.

    With that being said, I have several menus all using this single function (using different ID names) - would there be a way to put a single onclick in the body that would affect all?

  4. #4
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not a javascript guy, so copying and pasting is my thing not editing code


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
  •