Results 1 to 5 of 5

Thread: On Click Display Div

  1. #1
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Arrow On Click Display Div

    Hey Guys,

    I will try to keep this short. I'm trying to achieve something like this:
    http://www.promotionalcodes.org.uk/n...and-discounts/
    (Please click on the "Click to Reveal Code & Open Site" button)

    Notice how the button disappears and a new area appears. This is basically what I want to achieve. I have a similar site setup, for which I want to implement this one.
    http://www.fashiondiscountvouchers.com/test1

    I'm thinking, upon the click of the button, the first div disappears and the second one appears. How do I achieve this? Is there a tutorial anyone is aware of?

    I know my HTML/CSS well, but I haven't done things like this. Sorry for being a little stupid.

    Thanks and appreciate a speedy response.

    Thanks

    Adnan

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    You can play around with this:
    [code[
    <style type="text/css">
    #box {
    height: 100px;
    width: 100px;
    background: lightblue;
    }
    #box2 {
    height: 100px;
    width: 100px;
    background: blue;
    visibility: hidden;
    }
    </style>
    <div id="box" onclick="document.getElementById('box').style.visibility = 'hidden';
    document.getElementById('box2').style.visibility = 'visible';">&nbsp;</div>
    <div id="box2">&nbsp;</div>
    [/code]
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    Adnan959 (09-28-2010)

  4. #3
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Yes, something like the solution proposed by Nile. More generally (using javascript):
    Code:
    <head>
    <style type="text/css">
    #box1 {
    position:absolute;
    height: 100px;
    width: 100px;
    background: lightblue;
    display:inline
    }
    #box2 {
    position:absolute;
    height: 100px;
    width: 100px;
    background: blue;
    visibility: hidden;
    display:inline
    }
    #box3 {
    position:absolute;
    left:120px
    }
    </style>
    
    <script type="text/javascript">
    function change_div(this_div,that_div,code)
    {
    document.getElementById(this_div).style.visibility = 'visible';
    document.getElementById('box3').innerHTML=code;
    document.getElementById(that_div).style.visibility = 'hidden';
    }
    </script>
    
    </head>
    
    <body>
    <div id="box1" onclick="change_div('box2','box1','Here is the code &rarr; \'FREEDEL\'')">&nbsp;</div>
    <div id="box2" onclick="change_div('box1','box2','Get your code')">&nbsp;</div>
    <div id="box3">Get your code</div>
    
    </body>
    ===
    Arie Molendijk.

  5. The Following User Says Thank You to molendijk For This Useful Post:

    Adnan959 (09-28-2010)

  6. #4
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks Nile and molendijk. That really did help.

    I've been able to set this up now.

    Thanks a lot once again for being of such a great help. Appreciate it.

  7. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem, I'm glad to help.

    Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved when an issue is fixed. To make the status of the thread resolved:
    1. Go to your first post
    2. Edit your first post
    3. Click "Go Advanced"
    4. In the dropdown next to the title, select "RESOLVED"
    Jeremy | jfein.net

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
  •