以下我试图追踪插入到p-msg-class
类中的最后一个元素,但由于其他元素动态插入到.middle-ui,.flt-rt,.content-ht
中,所以我看到该警告很多次。我怎么能只跟踪p-msg-class
,并警告停止所有其他HTML动态插入jquery获取特定类的味精
$('.middle-ui,.flt-rt,.content-ht').bind('DOMNodeInserted', function(event) {
if($(this).find(".visitor-msg-cont").last().find(".p-msg-class").length > 0)
{
alert($(this).find('.visitor-msg-cont').last().find('.p-msg-class').last().html());
}
});
你试过'find('。p-msg-class:last')'? – 2013-03-26 14:33:55
是的,但它怎么会每次解决问题的前例:class =“new”插入我得到警报.. – Rajeev 2013-03-26 14:35:08
哦,我看到现在的问题是什么。所以,你必须找出插入的元素类是什么,如果它是'p-msg-class',那么执行警报。新元素是否总是附加到最后? – 2013-03-26 14:42:38