0

I set up this fiddle with an issue I am encountering. I need the script to hide the button that was clicked after the animation is complete. What is the correct way to do this?

http://jsfiddle.net/digitalaxis/utJKU/

HTML:

<div>
    <a id='button1' href="#">Button 1</a>
    <a id='button2' href="#">Button 2</a>
    <a id='button3' href="#">Button 3</a>
    <a id='button4' href="#">Button 4</a>
    <a id='button5' href="#">Button 5</a>
</div>
<div id="box">
    Some element
</div>

JS:

$('a[id^="button"]').click(function() {    
    $('#box').hide('slow', function() {        
        $('a').hide('slow');
    });
});
2
  • Try this: jsfiddle.net/mHjtS Commented Jul 10, 2012 at 20:56
  • 1
    I know you already have your solution, but you should provide the code sample directly in the post itself, so I have moved it over here. The idea is to think of the question as being self-contained if external resources like jsFiddle are ever unavailable. Commented Jul 10, 2012 at 21:02

1 Answer 1

8

set a global variable where receive $(this), and use in the call back, like this:

$('a[id^="button"]').click(function() {
   var $this = $(this);
   $('#box').hide('slow', function() {
        $this.hide('slow');
   });
});​
Sign up to request clarification or add additional context in comments.

Comments

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.