Results 1 to 5 of 5

Thread: Show button

  1. #1
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Show button

    I need a show button when is clicked it disappears and on that place shows text , image or an video.Even button doesn't have to look as a button , it can be image or a text.I have found that on http://nba.lemons.se/ and on that site it shows result when button is clicked , I need something similar but can't find html code for that.If someone knows that , please post html code of that button.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    A very basic idea that should help you more forward:
    HTML Code:
    <span onclick="var el=document.getElementById('container');el.style.display=el.style.display=='none'?'':'none';" style="cursor:pointer;">Click me to show/hide element</span>
    <div id="container" style="display:none;"><br />This is the text</div>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Button should disappear when is clicked and on the very same place should show text , image or an video.

  4. #4
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    In a nutshell, this should work:
    Code:
    <span onclick="this.style.display='none';document.getElementById('container').style.display=''" style="cursor:pointer;">Click me to show element</span>
    <div id="container" style="display:none;"><br />This is the text</div>
    However, things varies as to what you wanted get done really, but the code above should demonstrate how to alter an element's display through JS.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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

    jojo_molat (04-23-2011)

  6. #5
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I can think of two ways of doing this. One without the use of jQuery, and another using jQuery, which is my preference.

    Without jQuery:

    Code:
    <div onclick = "this.style.display='none';document.getElementById('content_container').style.display='block'">My super button</div>
    <div id = "content_container" style = "display:none">
        My content that was hidden but its visible now that I clicked on my button.
        Insert your video, image, etc here.
    </div>
    Of course you can just define your CSS for both fields in an external css file. (The preferred method), but this gives you an idea.

    You can do this in a much simpler way with jQuery. All you have to do is add jQuery javascript package file. And then rewrite the code above as:

    Code:
    <div onclick = "$(this).toggle(); $('content_container').show()">My super button</div>
    <div id = "content_container" style = "display:none">
        My content that was hidden but its visible now that I clicked on my button.
        Insert your video, image, etc here.
    </div>
    You added a new message after I started writing this. If you want everything to happen within the same DIV block, then you can nest the divs:

    Code:
        <div class = "GlobalSuperContainer">
            <input type = "button" value = "My Button" onclick = "$(this).toggle(); $('content_container').show()">
            <div id = "content_container" style = "display:none">
                My content that was hidden but its visible now that I clicked on my button.
                Insert your video, image, etc here.
            </div>
        </div>
    I strongly suggest you start using jQuery for these types of things. You will not regret you started learning it now.

    A more proper way would be probably to use jQuery's command hide(), instead of toggle(), but it's essentially the same thing.
    Last edited by devogirl; 04-26-2011 at 06:20 AM.

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
  •