ajax - Rails js action won't run code after partial render -


i'm trying add newly created partial existing list of partials gets rendered in create.js.erb controller action response, , nice scroll item , indicate new addition highlighting or something. have gotten hang of scrolling part in client side javascript, effects come after partial render in create.js.erb don't run. there plenty of examples of being possible, i'm not sure why mine doesn't work.

first try: create.js.erb

$('#alltab').removeclass('active'); $('#activetab').addclass('active'); $('#completetab').removeclass('active'); // todo: make sure li below gets id="campaign_####" before render happens. $('#activetablist').append("<li><%= escape_javascript(render partial: 'fundraisers/fundraiser', locals: {f: @fundraiser, g: @group}) %></li>") var number_li = $('#activetablist li').length; var $newcampaigndiv = $('#activetablist li').last().children("panel"); $('#number_of_campaigns').text('campaigns (' + number_li + ')'); $("body").animate({     scrolltop: $newcampaigndiv.offset().top }, {     duration: 600,     queue: false }); $('#activetablist li').last().children("panel").effect('highlight'); 

second try: create.js.erb

$('#alltab').removeclass('active'); $('#activetab').addclass('active'); $('#completetab').removeclass('active'); // todo: make sure li below gets id="campaign_####" before render happens. $.when($('#activetablist').append("<li><%= escape_javascript(render partial: 'fundraisers/fundraiser', locals: {f: @fundraiser, g: @group}) %></li>")).done(function () {     var number_li = $('#activetablist li').length;     var $newcampaigndiv = $('#activetablist li').last().children("panel");     alert('gets here @ least');     $('#number_of_campaigns').text('campaigns (' + number_li + ')');     $("body").animate({         scrolltop: $newcampaigndiv.offset().top + $newcampaigndiv.height() / 4 - $(window).height() / 2     }, {         duration: 600,         queue: false     });     $('#activetablist li').last().children("panel").effect('highlight'); }); 

i hesitant ask question because i'm not opposed accepting fact i'm not traversing dom correctly, i've been trying sorts of combinations right.

also:

if try embed more ruby set id of <li> surrounding partial, breaks whole action , partial not rendered. idea i'm missing here?


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -