[英]Highlighting a newly added item using jQuery
当用户将新评论(divCommentHtml)添加到评论列表(divComments)时,我想突出显示它几秒钟并使其消失。 你怎么用jquery做到这一点? 这似乎不起作用:
$('#divComments').prepend($divCommentHtml).effect("highlight", {}, 2000);
谢谢!
使用prepend
,您可以在#divComments
元素上运行UI效果。
试试这个(假设$divCommentHtml
是一个jQuery对象)
$divCommentHtml.prependTo('#divComments').effect('highlight', {}, 2000);
也许
$('#divComments').prepend($divCommentHtml)
.find(':first').effect('highlight', {}, 2000);
jQuery没有开箱即用的effect()
。 更新哦,这是一个jQuery UI。 继续 :)
$divCommentHtml.prepentTo('#divComments').effect("highlight", {}, 2000);
我更改了它的工作方式,以便在实际的$divCommentHtml
对象上运行您的方法。
另一种选择是给$ divCommentHtml一个ID,然后在预先添加效果后运行效果
$divCommentHtml = '<div id="myID">Some Contents</div>'
$('#divComments').prepend($divCommentHtml);
$( "#myID" ).effect( 'highlight', {}, 2000);
您在divCommentHtml
周围缺少括号。 查看Live demo
$('#divComments').prepend($(divCommentHtml)).effect("highlight", {}, 2000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.