Results 1 to 2 of 2

Thread: Show/hide element[Java]

  1. #1
    chabuya Guest

    Question Show/hide element[Java]

    Hey there,
    I want a div element only to show when you hover over an anchor of the main menu.
    The problem is: This div is not a child of the menu, so i can't do it through simple hover and display css functions.


    That's the menu.


    This is what should appear when you're hovering one of the items.
    Also, I want a different div for the different menu anchors, because I dont think wordpress can read the category by a hover. And, if this wasn't enough, I have no idea how to build this so you can actually from the menu anchor to the subnav without it disappearing when you're not above the anchor.

    I already tried hundreds of show/hide scripts, solving this via css but nothing works for me.
    I'd be grateful for any suggestions.

    Thanks in advance,
    Kevin

    [Moderator edit - No signatures / advertising for non-established members.]
    Last edited by Alan; 20 Feb 2010 at 03:04 PM.

  2. #2
    Join Date
    Nov 2009
    Posts
    27
    Could you try something like...

    Code:
    <a href="wherever" onmouseover="document.getElementById('div').style.display=''"
    onmouseout="document.getElementById('div').style.display='none'">Free Resources</a>
    Give the div an id and used the id name in place of the red 'div' in the code above. If you don't want the div to disappear when you move the mouse cursor away, you can just remove the onmouseout event.

    Because you have a number of menu items, it may actually be better to create a function to show/hide the correct div...

    Code:
    <script type="text/javascript">
    function toggleDivs(showDivId){
        var div1 = "none";
        var div2 = "none";
        var div3 = "none";
        var div4 = "none";
    
        switch(showDivId){
            case 'div1': div1 = ""; break;
            case 'div2': div2 = ""; break;
            case 'div3': div3 = ""; break;
            case 'div4': div4 = ""; break;
        }
    
        document.getElementById('div1').style.display=div1;
        document.getElementById('div2').style.display=div2;
        document.getElementById('div3').style.display=div3;
        document.getElementById('div4').style.display=div4;
    }
    </script>
    <div id="div1" style="display: none">Free Resources</div>
    <div id="div2" style="display: none">Graphic Design</div>
    <div id="div3" style="display: none">Photography</div>
    <div id="div4" style="display: none">Tutorials</div>
    <a href="wherever" onmouseover="toggleDivs('div1')">Free Resources</a>[/
    <a href="wherever" onmouseover="toggleDivs('div2')">Graphic Design</a>[/
    <a href="wherever" onmouseover="toggleDivs('div3')">Photography</a>[/
    <a href="wherever" onmouseover="toggleDivs('div4')">Tutorials</a>
    This will bascially hide all divs except for the one whose id you pass to the function. The divs should remain visible until another menu item is hovered.

    p.s. I've not

Similar Threads

  1. Show/hide div on page load
    By denno020 in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 23 Dec 2009, 10:57 PM
  2. problem with a show/hide toggle thing (JS)
    By belledumonde in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 26 Aug 2006, 08:33 PM

Posting Permissions

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