This works:
$('#products.table tr').click ->
$(@).toggleClass('row_selected')
This doesn't:
$('#products.table tr').live 'click', (event) ->
$(@).toggleClass('row_selected')
Error in browser's console:
[Error] TypeError: 'undefined' is not a function (evaluating '$('#products.table tr').live')
ready (products.js, line 10)
fire (jquery.js, line 3049)
fireWith (jquery.js, line 3161)
ready (jquery.js, line 434)
pleted (jquery.js, line 105)
What am I missing?
This works:
$('#products.table tr').click ->
$(@).toggleClass('row_selected')
This doesn't:
$('#products.table tr').live 'click', (event) ->
$(@).toggleClass('row_selected')
Error in browser's console:
[Error] TypeError: 'undefined' is not a function (evaluating '$('#products.table tr').live')
ready (products.js, line 10)
fire (jquery.js, line 3049)
fireWith (jquery.js, line 3161)
ready (jquery.js, line 434)
pleted (jquery.js, line 105)
What am I missing?
Share Improve this question edited Sep 7, 2013 at 1:20 Meltemi asked Sep 7, 2013 at 1:10 MeltemiMeltemi 38.4k52 gold badges201 silver badges298 bronze badges1 Answer
Reset to default 7live has been deprecated as of jQuery version 1.7, and Rails 3's default jQuery version is 1.9. You need to use on instead:
Try:
$(document).on 'click', '#products.table tr', (event) ->
if ( $(@).hasClass('row_selected') )
$(@).removeClass('row_selected')
else
$(@).addClass('row_selected')
or, you could use the toggleClass
method as suggested in the ments as:
$(document).on 'click', '#products.table tr', (event) ->
$(@).toggleClass('row_selected')
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745193763a4615990.html
评论列表(0条)