Using jQuery and coffeescript, I want to update a html element when user presses enter. My code looks like this:
$ ->
$('p span').live 'keypress', (e) ->
if e.keyCode == 13
$('div.sidebar-nav ul li a.active').html $(this).attr 'value'
Coffeescript compiles without any errors, but the code is not working. For some reason, if I add change the code to following it works:
$ ->
$('p span').live 'keypress', (e) ->
if e.keyCode == 13
alert 'some string'
$('.sidebar-nav a.active').html $(this).attr 'value'
I spend last few hours trying to solve this and still nothing. Any help would be deeply appreciated.
$ ->in coffeescript?$is just a function.->introduces an anonymous function. CoffeeScript also adds calling functions without parentheses. Put the pieces together, and you get$(function() { /* ... */ });'value'is another argument, it's not, because there's no comma.