Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

javascript swap image & swap links

Posted on 2009-12-30
6
Medium Priority
?
873 Views
Last Modified: 2012-05-08
I am using swapimage jquery code (http://code.google.com/p/jquery-swapimage/) to swap out a number of images when a corresponding button is clicked. Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
            <title></title>
            <meta http-equiv="content-type" content="text/html; charset=utf-8" />
            <link rel="stylesheet" type="text/css" href="css/style.css" />
            <script type="text/javascript" src="js/scripts.js"></script>
            <!-- jQuery scripts for Home page theater -->
            <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
      <script type="text/javascript" src="js/jquery.metadata.min.js"></script>
      <script type="text/javascript" src="js/jquery.swapimage.min.js"></script>
            <script type="text/javascript">
                  $.swapImage(".swapImage");
                  $.swapImage(".swapImageClick", true, true, "click");
                  $.swapImage(".swapImageDoubleClick", true, true, "dblclick");
                  $.swapImage(".swapImageSingleClick", true, true, "click");
                  $.swapImage(".swapImageDisjoint");
            </script>
            
            
      </head>
      <body>                  
                  <div id="theater_wrap">
                        <div id="theater_main">
                              <div style="width:386px;">
                                    <a href=""><img id="main" src="images/theater-plan.jpg" id="main" alt="" width="386" height="288" /></a>
                              </div>
                        </div>
                        <div id="theater_nav">
                              <a href=""><img src="images/tag-plan.gif" id="tag" alt="" class="tag" width="541" height="213" /></a>
                              <div><img class="swapImageSingleClick { sin: ['#main:images/theater-honest.jpg','#tag:images/tag-honest.gif','#btn1:images/theater_btn1_on.gif'] }" src="images/theater_btn1_off.gif" id="btn1" alt="" />
                              <img class="swapImageSingleClick { sin: ['#main:images/theater-control.jpg','#tag:images/tag-control.gif','#btn2:images/theater_btn2_on.gif'] }" src="images/theater_btn2_off.gif" id="btn2" alt="" />
                              <img class="swapImageSingleClick { sin: ['#main:images/theater-plan.jpg','#tag:images/tag-plan.gif','#btn3:images/theater_btn3_on.gif'] }" src="images/theater_btn3_off.gif" id="btn3" alt="" />
                              <img class="swapImageSingleClick { sin: ['#main:images/theater-solutions.jpg','#tag:images/tag-solutions.gif','#btn4:images/theater_btn4_on.gif'] }" src="images/theater_btn4_off.gif" id="btn4" alt="" /></div>
                        </div>
                  </div>
                  
                        
      </body>
</html>

That part is working fine, but I also need to swap the link URLs that surround the #main image and #tag image onClick but am unsure of how to do that.

Related jscripts are here:
http://www.koders.com/javascript/fid8808552E4A4E62313EB9AD8B309FA36B2FE3AE73.aspx?s=%22Yehuda+Katz%22
0
Comment
Question by:tekgrl
  • 3
  • 3
6 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 26157098
what does "swap the link URLs" mean?
0
 

Author Comment

by:tekgrl
ID: 26157862
Swap the <a href> around the images.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 26160457
those <a href=""> does not do anything just adding a pointer cursor (I guess, unless the library used here is adding something at run time)

or did you remove the href on purpose? just I could not get the issue here...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:tekgrl
ID: 26162383
I left them blank because the link points to different places based on what image is loaded. <a href="page1.html>, <a href="page2.html>, <a href="page3.html>, etc.
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 26172637
ok, you can do this...

on the link, there is a full swap code, here
http://www.koders.com/javascript/fid24987C84A3A5E65DEFD861BAF5838AF68CEEE959.aspx?s=%22Yehuda+Katz%22
use this

modify the links to similar to this:

<a href="page1.htm" href2="page1_alt.htm">...

then  modify jQuery.swapImage.swap with this & add a new function to swap links

jQuery.swapImage.swap = function() {
		var data = jQuery(this).metadata();
		var tmp = data.src;
		data.src = this.src;
		this.src = tmp;
swapLinks(this);
	};

function swapLinks(img){
  var a = img.parentNode;
  var tmphref = a.href;
  a.href = a.href2;
  a.href2 = tmphref;
}

Open in new window

0
 

Author Comment

by:tekgrl
ID: 26179990
That didn't work. I've attached my code.
jquery.swapimage.js
test.html
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question