Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

$('.js-preview-container').slideToggle 300, -> @remove()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top