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
    Aug 2010
    Posts
    31
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Swap content inside a div when link clicked

    Hello

    I want to change the content of a <div> (or swap divs?)when a user clicks a link just below it.
    What is the best method for doing this? It's only a small bit of html content inside the div that i need to swap when someone clicks a link just below it.

    E.g

    <div>
    {html content 1}
    </div>

    (link to replace content 1 with hidden content 2)

    Many thanks if you can help,

    Tree

  • #2
    Regular Coder
    Join Date
    Nov 2009
    Location
    Florida United States
    Posts
    105
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Use javascript to switch display from none to inline or block using the onClick action.
    New Coder!!!!

  • Users who have thanked calebandchels for this post:

    treetops (02-08-2012)

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    73
    Thanks
    5
    Thanked 9 Times in 9 Posts
    Code:
    <div id="mydiv"> This is the original content </div>
    <p>&nbsp;</p>
    <a href="#" onClick="swap()">Link text Here</a>
    Code:
    <script type="text/javascript">
    function swap() {document.getElementById("mydiv").innerHTML="NEW HTML CONTENT HERE";}
    </script>
    This should do what you need

  • Users who have thanked ARCLite Studio for this post:

    treetops (02-08-2012)


  •  

    Posting Permissions

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