I have some javascript that looks like this:
$('button').on('click', function(e){
alert($(this).text());
});
How would I convert this to coffeescript?
I have some javascript that looks like this:
$('button').on('click', function(e){
alert($(this).text());
});
How would I convert this to coffeescript?
You could express this in CoffeeScript as:
$('button').on 'click', (e) ->
alert $(@).text()
The CoffeeScript website has a great "Try CoffeeScript" feature that shows you the output JS. Here's an example of your code.
$('button').on('click', function(e) { return alert(this.text); }); It's missing the $ and the method call after textMy best guess is that the compiler you're using is out of date since this page shows that
$ ->
$('#network_select select').on 'change', (e)->
alert $(@).val()
Should compile into
$(function() {
return $('#network_select select').on('change', function(e) {
return alert($(this).val());
});
});
Which does have the argument to your change handler. If the compiler is not the problem, then you are missing something in your question.