문제

I'm trying to remove an element on click, however remove stops the slideToggle from happening.

$('.js-preview-close').click ->
$('.js-preview-container').slideToggle(1000).remove();

I believe I need to do a callback from within slideToggle, but I just switched to Coffescript and am not sure how to write it. If it were jQuery could it just be:

$('.js-preview-container').slideToggle(300, function(){$(this).remove()});

How do I do this in Coffeescript? Thanks.

도움이 되었습니까?

해결책

$('.js-preview-container').slideToggle 300, ->
  @remove()

다른 팁

In CoffeeScript the @ replaces the this keyword. So try this:

$('.js-preview-container').slideToggle 300, -> @remove()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top