I had a model with some nested attributes and needed to add new items via Javascript. This is what I came up with:
$('.add_task').click(function() {
var last_item = $('#tasks li:last');
last_item.after('<li>'+last_item.html().replace(/\d+(?=\_)|\d+(?=\])/g, function(match) {return parseInt(match)+1;})+'</li>');
});
It does the job just fine, but was wondering if anyone has a better suggestion.
Cheers!