Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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

$('.js-preview-container').slideToggle 300, -> @remove()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top