• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 28
  • Last Modified:

How can I get this image to change when I toggle some content?

Head out to http://brucegust.com/eResume/

In the upper right hand corner, there's a little downarrow button that you can click on that reveals some content. When you click it, the arrow changes to "up." I want to change it back to "down" when the user clicks on it again to minimize the expanded content.

How?

You can see where I started in my code with this:

$('#instructions').click(function(event){
		event.preventDefault();
		//$("#the_button").attr("src", "images/minimize_button.png");
		var src = $('#the_button').attr('src');
		if(src="images/expand_button.png")
		{
			$("#the_button").attr("src", "images/minimize_button.png");
		}
		else
		{
			$("#the_button").attr("src", "images/expand_button.png");
		}
		$('#instruction_row').slideToggle(300);
	});

Open in new window


I think I'm close, but I got stuck.

Thanks!
0
brucegust
Asked:
brucegust
  • 2
  • 2
2 Solutions
 
leakim971PluritechnicianCommented:
replace your whole code by the following one :
<script>
$(document).ready(function(e) {
	$('img[usemap]').rwdImageMaps();
	
	$('area').on('click', function() {
		//alert($(this).attr('alt') + ' clicked');
	});
	
	$('#instructions').click(function(event){
		event.preventDefault();
		$('#instruction_row').slideToggle(300, function() {
			var src = $("#instruction_row .col-xs-12").is(":visible") ?  "images/expand_button.png" : "images/minimize_button.png";
			$("#the_button").attr("src", src);
		});
	});
});
</script>

Open in new window

0
 
Vish KTechnologistCommented:
Hello,
you have error in your condition thats why it is not working as expected. If you change it to two == signs, it will work fine.
if(src="images/expand_button.png") { 

Open in new window



I have modified your code to be little more stable.
$('#instructions').click(function(event) {
  event.preventDefault();
  $('#instruction_row').slideToggle(300, function() {
    if ($('#instruction_row').css('display') === 'block') {
      $('#the_button').attr('src', 'images/minimize_button.png');
    } else {
      $('#the_button').attr('src', 'images/expand_button.png');
    }
  });
});

Open in new window

0
 
brucegustPHP DeveloperAuthor Commented:
Vish!

I just realized I blew right past your contribution! So, sorry!

I'll ask one of the moderators to open up the question so I can honor you with some points.

Thanks!
0
 
Vish KTechnologistCommented:
Thanks bruce,
let me know if my contribution helped.
0
 
brucegustPHP DeveloperAuthor Commented:
I went with Leak's solution, but Vish - I'm taking notes and putting your solution into my "files" for future reference. Thanks both of you!
0

Join & Write a Comment

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now