Page 1 of 1

Swapping images?

Posted: Sat Mar 26, 2011 11:20 am
by psychotomus
Heres a snipplet from my JS file..

Code: Select all

	$("#next").mouseup(function () {
		$.ajax({
		      url: "ajax/userSlider.php?userID=" + lastUserID,
		      global: false,
		      type: "GET",
		      dataType: "html",
		      success: function(msg){    
			  	userSplit = new Array();
			  	userSplit = msg.split(":");
				
				if(userSplit[0] == "Ok")
				{
					$("#img_1a").attr("src", $("#img_2b").attr("src"));
					$("#img_1b").attr("href",$("#img_2a").attr("href"));
					alert($("#img_2b").attr("src"));
					$("#img_2a").attr("src", $("#img_3b").attr("src"));
					$("#img_2b").attr("href",$("#img_3a").attr("href"));

					$("#img_3a").attr("src", $("#img_4b").attr("src"));
					$("#img_3b").attr("href",$("#img_4a").attr("href"));
					
					
				}   		         
Now I hardcoded my userSplider.php for now so userSplit[0] always returns Ok.
alert($("#img_2b").attr("src")); always returns the src value of img_2b so thats not the problem.

The problem is it doesn't switch all the images. I also get no errors from my FireFox Error Console.

Page www.psprpg.info

Re: Swapping images?

Posted: Sun Mar 27, 2011 6:31 am
by dgreenhouse
It appears you're mixing src with href

Maybe this:

Code: Select all

var src1 = $("#img_1a").attr("src");
var href1 = $("#img_1b").attr("href");

$("#img_1a").attr("src", $("#img_2a").attr("src"));
$("#img_1b").attr("href",$("#img_2b").attr("href"));

$("#img_2a").attr("src", $("#img_3a").attr("src"));
$("#img_2b").attr("href",$("#img_3b").attr("href"));

$("#img_3a").attr("src", $("#img_4a").attr("src"));
$("#img_3b").attr("href",$("#img_4b").attr("href"));

$("#img_4a").attr("src", src1);
$("#img_4b").attr("href", href1);