Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

change img src with jQuery

Posted on 2011-02-28
3
Medium Priority
?
2,036 Views
Last Modified: 2012-05-11
I don't understand why I can't chnage the image by chaning the src. What am I doing wrong?


<td id="TagLine" colspan="2" align="right"><?php echo '<img id="DoYouMeasureUp" src="'.BASEURL .$taglinefile .'" alt="'.$_SESSION['lang']['tagline'] .'" width="296" height="44"/>'?>
	</td>

Open in new window


I added this in a jQuery and tried all three different ways to define path to file
	$("#sLangSelect").live('change', function(){
		
		var myLanguage = $(this).val();
		//runReport();
		//$("#headerSection").load('/aaMain/header.php');
		switch (myLanguage)
		{
			case '1':
				
				$('img').attr('src') = '/images/do-you-measure-up-english.gif';
	
				break;
			case '2':
				
				$('#DoYouMeasureUp').attr('src')= "images/do-you-measure-up-french.gif";
			
				break;
			case '3':
				
				$('#DoYouMeasureUp').attr('src')= "http://dev.secure.emetrixsystems.com/images/do-you-measure-up-spanish.gif";
				
				break;
		}
		
		
	/*	var rt = $.ajax({
	   type: "POST",
	   url: "/aaMain/header.php?ulang="+$(this).val(),
	   //data: $("form[name=filters]").serialize(),
	   success: function(msg){
$("#headerSection").html(msg); }
});*/

		
});
       

Open in new window

0
Comment
Question by:gbeaulac
  • 2
3 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 34998131
For example :

$('img').attr('src', '/images/do-you-measure-up-english.gif');

Open in new window


and not :

$('img').attr('src') = '/images/do-you-measure-up-english.gif';

Open in new window

0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 34998147
with select the image by its id and not it tag, use the # :


$
('#imgId').attr('src', '/images/do-you-measure-up-english.gif');

Open in new window

0
 

Author Closing Comment

by:gbeaulac
ID: 34998180
You are the Man!!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 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