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.
is different than…
in the first case,
a.activeis a descendant of.sidebar-nav, and the structure under.sidebar-navcould be anything (list, article, spans, marquees, doesn’t matter, as long as its in there somewhere). In the second, it is a great-grandchild, within a list. We’d need to see your HTML to be sure, but it looks like bad selectors…