SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Swapping script

  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Swapping script

    Hi there, I was wondering if you guys could help me with a js here.

    You see, I wan't to have an image with the text "show". When pressing this image, it will disappear, and another div appears. Inside this div, I wan't to have a image with the text "hide", which will hide the div, and show the "show" image.

    I was also wondering about how to show/hide/swap two divs. F.i:
    Code:
    <a href="XX"><img /></a> /// by clicking this, the script should hide this image/link and show div1 and div2
    
    <div id="1">
    XX
    </div>
    
    <p>XX</p>
    
    <div id=2">
    XX
    </div>
    (If this is impossible or too hard, I would really wan't a script that shows div(s) with class="XX")

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Code html4strict:
    <img id="toggle" src="show.jpg?toggle=hide.jpg">

    Code javascript:
    document.getElementById('toggle').onclick = function () {
        var split = this.getAttribute('src').split('?');
        var image1 = split[0];
        var image2 = split[1].split('=')[1];
        this.setAttribute('src', image2 + '?toggle=' + image1);
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •