以下我試圖追蹤插入到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