[英]Can't get .show() to work on ajax success
Below is the code that I am having problems with. 以下是我遇到问题的代码。 The issue is the 2 specific lines where i am transversing the DOM and attempting to execute .show() on .cell-toolbar a[href$="#edit"] and .cell-toolbar a[href$="#delete"]' respectively.
问题是我要遍历DOM并尝试在.cell-toolbar a [href $ =“#edit”]和.cell-toolbar a [href $ =“#delete”上执行.show()的2条特定行]' 分别。 And as shown below, i have attempted to execute .show in 2 different places, neither with any success.
如下所示,我尝试在2个不同的位置执行.show,但均未成功。 the console.log in the code below does return the appropriate jQuery object for the selector.
下面代码中的console.log确实为选择器返回了适当的jQuery对象。 Also worth noting I am on jQuery 1.2
另外值得注意的是我在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(); // Does not work
container.find('.cell-toolbar a[href$="#delete"]').show(); // Does 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(); // Does not work
container.find('.cell-toolbar a[href$="#delete"]').show(); // Does not work
console.log(container.find('.cell-toolbar a[href$="#edit"]'));
}
});
}
});
It could be that you're trying to access elements before the DOM has drawn them. 可能是您在DOM绘制元素之前尝试访问它们。 Try adding a slight delay:
尝试添加一些延迟:
container.append(data.node);
window.setTimeout(function() {
container.find('.cell-toolbar a[href$="#edit"]').show(); // Does not work
container.find('.cell-toolbar a[href$="#delete"]').show(); // Does not work
console.log(container.find('.cell-toolbar a[href$="#edit"]'));
},50)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.