2011-11-11 81 views
3

我用ajax调用来更新html。我需要为隐藏添加元素,然后将动画:如何将div隐藏为使用jQuery隐藏?

$.ajax({ 
    success: function (data, textStatus) { 
     $(".comments").prepend(data); 
     $(".comments .comment-frame:first").slideDown("slow"); // it doesn't work, since element is visible 

新增的数据:

<div class="comment-frame"> 
... 
</div> 

我不能修改CSS使一流comment-frame隐藏的,因为我已经有与页面上的其他元素同一班,应该保持可见。所以,不知何故,我应该加上data隐藏。我该怎么做?

+0

尝试'$( “意见”)。预定(数据).hide()' –

+0

是的.comment格在你的。点评DIV(你tyargetting)总是第一个div? –

+0

Innuendo,这是我的第一个预感,但我怀疑这将隐藏包裹元素.comments。 –

回答

8

你可以让一个jQuery对象出data.hide()之前.prepend()至来$(".comments")

$.ajax({ 
    success: function (data, textStatus) { 
     var $data = $(data).hide(); 
     $(".comments").prepend($data); 
     $(".comments .comment-frame:first").slideDown("slow"); 
6

使当插入它那是隐藏的包装:

$(".comments").prepend('<div style="display:none">'+data+'</div>');