0

i have managed to switch my crosshair to a minus using jquery but cannot write the query to reset on re-click. I'm trying and trying. The second/minus img is picked from the img directory.

my HTML-

<div id="button-1"><img id="crosshair" src="img/plus.jpg" alt="plus"></div>

Jquery (initial)-

$('#crosshair').on({
'click': function(){
    $('#crosshair').attr('src','img/minus.jpg');
}
});

thanks for any help!

  • check here: [Registering jQuery click, first and second click][1] [1]: http://stackoverflow.com/questions/14914372/registering-jquery-click-first-and-second-click – NimaNr Nov 30 '14 at 10:52

1 Answers1

0

Add a check condition.

$('#crosshair').on('click', function() {
  var $this = $(this);
  $this.attr('src', $this.attr('stc') === 'img/minus.jpg' ? 'img/plus.jpg' : 'img/minus.jpg');
});
xdazz
  • 158,678
  • 38
  • 247
  • 274