ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Hide/Show Div anyone?

April 20, 2008 5:02am

Subscribe [4]
  • #1 / Apr 20, 2008 5:02am

    zeedy2k

    33 posts

    Does anyone know how I can manage to do the following:
    http://www.myvouchercodes.co.uk/discounts/totalpda.co.uk

    If you can see it obscures the discount code below a div and doesnt display it under you click the button. Anyone know how I can do that… I dont know javascript or enough css to do it.

    Cheers
    Robert

  • #2 / Apr 20, 2008 6:23am

    geshan

    54 posts

    You’ll have to use some javascript and some css will be required. I suggest using Prototype Framework (http://prototypejs.org/) and script.aculo.us together to do what you want to. Its very easy you can do it with some lines of coding using above two frameworks.

  • #3 / Apr 20, 2008 6:26am

    xwero

    4145 posts

    If you use jQuery it’s simple to reveal your discountcode

    $('div.voucher_button a').bind('click',function(){
        $(this).hide();
    });
  • #4 / Apr 20, 2008 7:29am

    Lone

    350 posts

    And just to show how easy and still good looking jQuery is - here is how to toggle it:

    $('div.voucher_button a').click(function () {
          $('#target').slideToggle('slow');
    });

    http://docs.jquery.com/Effects/slideToggle

    Have a look into jQuery - heaps of stuff that makes javacsript stuff like this very simple to do!

  • #5 / Apr 20, 2008 5:35pm

    Sally D

    129 posts

    Hi I created a hide or show function for you with easy javascript

    all you do is feed it 2 arguments the div id and the event you want either hide or show

    function hide_show(id,event)
    {
    
      var div=document.getElementById(id);
      switch(event) 
      {
        
        case "show":
          div.style.display="block";
        break;    
        case "hide":
          div.style.display="none";
        break;
        default:
          alert("error");
       }
    }

    then in your div you would initially set up as display none then you add this function to an onclick event handler to one of your hyper links <a href=# onclick=“hide_show(‘id’,‘show’)”> click here to show</a>

    like that

    I could have used a if statement or even a ternary operator but I chose the switch for a switch

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases