I am new to javascript and starting to mix javascript + jquery + coffeescript together is not easy for a beginner like me ...
I created a very simple sortable list, and I would like to renumber my list on the fly (server side code is ok).
The coffeescript code I wrote is:
jQuery -> $('.simple_grid tbody').sortable axis: 'y' containment: 'parent' cursor: 'move' tolerance: 'pointer' update: (event,ui)-> $.post($(this).attr('dataupdateurl') + '/' + ui.item.attr('id') + '/reorder/' + ui.item.index()) $('tr > td > a > span.number').each (i, element) => $(element).html i
This creates a table of this kind
<table class= "simple-grid"> <tbody dataupdateurl = "xxx"> <tr> <td> <a href="some_link"><span class="number">1</span>text 1</a> </td> <td> <a href="some_link"><span class="number">2</span>text 2</a> </td> <td> <a href="some_link"><span class="number">3</span>text 3</a> </td> </tr> </tbody> </table>
I am trying to renumber what is inside the span.number elements when the update callback fires, but I get the following error message:
Elementindefined
Any help would be greatly appreciated! Thanks!
UPDATE: the problem was due to the fact that I missed the indentation in the last function:
$('span.number').each (i, element) => $(element).html i
source share