Results 1 to 7 of 7

Thread: On Click Image Change..

  1. #1
    Join Date
    Jul 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default On Click Image Change..

    I was creating a website, but I need the links to change from one look to another when I click on it, im not sure if this is written in HTML or what, please help me!

    BTW: Not on mouse over..

  2. #2
    Join Date
    Dec 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    <script type="text/javascript">
    function changeImg(img, newimg) {
    img.src = newimg;
    }
    </script>

    <img onclick="changeImg(this, 'blah.gif')" src="blah1.gif">

  3. #3
    Join Date
    Jul 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks! One last question, how do I make it into a link? lol

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <a href="page.html">
      <img src="image.png" onclick="this.src='image-clicked.png';">
    </a>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It works, but the image has a black box around it.. What do I do?

    BTW, thanks!

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    In the head:
    Code:
    <style type="text/css">
      a img, a.img {
        border-style: none;
      }
    </style>
    In the body:
    Code:
    <a class="img" href="page.html">
      <img src="image.png" onclick="this.src='image-clicked.png';">
    </a>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry for bumping this old thread, it was the first thing google has shown >.<

    Anyway, I'm trying to make the spoiler tags show images instead, but it seems I don't really know how to implement this codes to the spoiler code. It properly show spoiler1.png to spoiler2.png change, but it's a one time thing and it just stays at spoiler2.png no matter if it's hidden or not.

    Original:

    Code:
    <dl style="margin:20px; margin-top:5px; border: 0px solid #3bbfe7;" class="codebox">
    
    <dt style="height:22px;">
    <strong>Spoiler:</strong>
    <input type="button" value="Show" style="width:50px; font-size:10px; margin:0px; padding:0px;" onclick="var spoiler = $(this).parents('.codebox').find('.content').toggle('slow');
    if ( spoiler.toggle == 'none' ) { spoiler.toggle = 'none'; this.value = 'Show'; } else { spoiler.toggle = 'show'; this.value = 'Hide'; };
    return false;">
    </dt>
    <dd>
    <div class="content" name="spoiler" style="display: none;">{param}</div>
    </dd>
    
    </dl>


    After some edits:
    Code:
    <script type="text/javascript">
     function changeImg(img, newimg) {
     img.src = newimg;
     }
     </script>
    
    <dl style="margin:20px; margin-top:5px; border: 0px solid #3bbfe7;" class="codebox">
    
    <dt style="height:22px;">
    <input type="image" src="/images/buttons/spoiler1.png"  onclick="var spoiler = $(this).parents('.codebox').find('.content').toggle('slow'); 
    if ( spoiler.toggle == 'none' ) { spoiler.toggle = 'none'; this.value = 'Show'; changeImg(this, '/images/buttons/spoiler1.png');} else { spoiler.toggle = 'show'; this.value = 'Hide'; changeImg(this, '/images/buttons/spoiler2.png'); };
    return false;">
    </dt>
    <dd>
    <div class="content" name="spoiler" style="display: none;">{param}</div>
    </dd>
    
    </dl>
    Another version:
    Code:
    <dl style="margin:20px; margin-top:5px; border: 0px solid #3bbfe7;" class="codebox">
    
    <dt style="height:22px;">
    <input type="image" src="/images/buttons/spoiler1.png"  onclick="var spoiler = $(this).parents('.codebox').find('.content').toggle('slow'); 
    if ( spoiler.toggle == 'none' ) { spoiler.toggle = 'none'; this.src = '/images/buttons/spoiler1.png';} else { spoiler.toggle = 'show'; this.src = '/images/buttons/spoiler2.png'; };
    return false;">
    </dt>
    <dd>
    <div class="content" name="spoiler" style="display: none;">{param}</div>
    </dd>
    
    </dl>

    Yet another approach:
    Code:
    <dl style="margin:15px; margin-top:5px; border: 0px solid #3bbfe7;" class="codebox">
    <dt>
    <img src="/images/buttons/spoiler1.png"  onclick="var spoiler = $(this).parents('.codebox').find('.content').toggle('slow'); 
    if ( spoiler.toggle == 'none' ) { spoiler.toggle = 'none'; this.src = '/images/buttons/spoiler1.png';} else { spoiler.toggle = 'show'; this.src = '/images/buttons/spoiler2.png'; };
    return false;" />
    </dt>
    <dd class="content" name="spoiler" style="display: none;">{param}</dd>
    </dl>

    EDIT: Fixed, optimised and what's not~ Though I'm not sharing it if no one asks me for it, since no one cared to help me either >.>
    Last edited by Emeralda; 06-28-2011 at 11:16 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
  •