# jQuery handler for closing a login box

I'm sure there's a better more 'jQuery' like way of writing this. In particular the selector $(this).closest('div.login-box') being in there twice. Perhaps it's possible to use $(this)?

$('.close-box').click(function () {$(this).closest('div.login-box').slideToggle("400");
if ($(this).closest('div.login-box').attr('id') == "login-forgot") { clearForgottenPasswordInputs(); } });  ## 1 Answer You could combine the calls: if ($(this).closest('div.login-box')
.slideToggle("400")
.attr('id'))


However, I do not recommend this.
Although it will work, it's unnecessarily confusing.

• I dunno... if he just did loginbox_id = \$(this).closest('div.login-box').slideToggle("400").attr('id'); Then he could just do if (loginbox_id == "login-forgot") below it. I think it removes any confusion that may occur by placing animation calls inside a boolean statement. – daybreaker Jun 14 '11 at 21:02
• @day: Yes. However, it's still confusing to have a mutation and a property access in the same line. – SLaks Jun 14 '11 at 21:19