Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2004
    Location
    Minnesota
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Show and/or Hide Div layer on click!?!?

    OK... i have a div layer that i would like to be able to show/hide onClick..... Here is what I have so far....

    <script type="text/javascript">
    function HideOrShowDiv(lyr) {
    if (lyr.style.display=='none'){
    alert("showing");
    lyr.style.display='block';
    }else{
    alert("hiding");
    lyr.style.display='none';
    }
    }
    </script>


    Here is the page I am working on.... http://www.tiredealersites.com/experiments/css/

    I want to be able to click on the "Details" to show or hide the details for the item. The way it is right now it just hides the details button (because i am passing 'this' in the function to hide/show), so i need to somehow target the div with the details in it?! <a href="#" onClick="HideOrShowDiv(this)">view details</a>

    I hope this make some sense, any help would be greatly appreciated!!

    Cheers.

  • #2
    New Coder
    Join Date
    Aug 2004
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Wrap your "Details" into some other div with id "detailsdiv1" and send "1" as parameter to your function. Likewise change other items also.

    Also you need to change your function like this.

    Code:
    function HideOrShowDiv(itemno) {
    var lyr=document.getElementById('detailsdiv'+itemno);
    if (lyr.style.display=='none'){
    alert("showing");
    lyr.style.display='block';
    }else{
    alert("hiding");
    lyr.style.display='none';
    }
    }
    Hope this will work for you...

    Afru.

  • #3
    New Coder
    Join Date
    Dec 2004
    Location
    Minnesota
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Got it, works.... Thanks Afru!


  •  

    Posting Permissions

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