2

I've got a problem with the toggle event. As you can see with this jsfiddle, I'm trying to create the yosemite menu bar with jquery.

I'm using :

$('.apple-button').click(function(event){
   event.stopPropagation();
});

I want the apple logo to return black when I click again on it. It only returns black when I click somewhere else. I know that I should have used the background property of my button to insert the image but I'm sure we can do it like this.

I tried to create a boolean to know if the button is active or not, but it doesn't work..

Any help ? Thanks

2
  • I updated my fiddle. Please take a look at it. I had to add the conditional code to the html click event. You can find the fiddle here Commented Dec 27, 2014 at 15:32
  • 1
    Thanks! I'm not sure this is necessary to duplicate the conditional code in the html click event. Juste need to set the variable black to true. Please have a look here Commented Dec 27, 2014 at 15:45

1 Answer 1

2

You want to add some conditional code in there... I added:

if(black === true){
    $('.apple-img').attr('src', 'http://img11.hostingpics.net/pics/396482apple.png');
    black = false;
} else {
    $('.apple-img').attr('src', 'http://img11.hostingpics.net/pics/233770appleblack.png');
    black = true;
}

After making the global variable black and setting it to true:

var black = true;

Updated Fiddle Here

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, a little somthing was missing... Here is the solution jsfiddle.net/roddr8mu/5. Thanks King Shimkus

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.