jquery - Can't get .show() to work on ajax success -
below code having problems with. issue 2 specific lines transversing dom , attempting execute .show() on .cell-toolbar a[href$="#edit"] , .cell-toolbar a[href$="#delete"]' respectively. , shown below, have attempted execute .show in 2 different places, neither success. console.log in code below return appropriate jquery object selector. worth noting on jquery 1.2
$('.bstory-page-preview .cell').droppable({ scope: 'cells', hoverclass: 'cellhover', drop: function(event, ui) { var container = $(this); container.find('.cell-toolbar a[href$="#edit"]').show(); // not work container.find('.cell-toolbar a[href$="#delete"]').show(); // not work var toolbar = container.find('.cell-toolbar').clone(); container.html(toolbar); var nid = getnid($(ui.draggable)); var did = getdid($(this)); var region = $(this).attr('data-region'); $.ajax({ url: drupal.settings.basepath + 'bstory/page/' + did + '/' + region + '/' + nid + '/save', datatype: 'json', success: function(data) { container.append(data.node); container.find('.cell-toolbar a[href$="#edit"]').show(); // not work container.find('.cell-toolbar a[href$="#delete"]').show(); // not work console.log(container.find('.cell-toolbar a[href$="#edit"]')); } }); } });
it you're trying access elements before dom has drawn them. try adding slight delay:
container.append(data.node); window.settimeout(function() { container.find('.cell-toolbar a[href$="#edit"]').show(); // not work container.find('.cell-toolbar a[href$="#delete"]').show(); // not work console.log(container.find('.cell-toolbar a[href$="#edit"]')); },50)
Comments
Post a Comment