0

I'm using DOMNodeInserted MutationEvent, is any way to select only new inserted elements by using this event? I have to add class to all inputs when they are inserted to document. I'm inserting new inputs to form via AJAX request but I can't add it there because this part have to work independently.

4

1 回答 1

1

ev.target您可以使用 jQuery 的方法获取插入的元素并检查is()标签名称。

例如:

$(document).on('DOMNodeInserted', function(ev){
    var _self = $(ev.target);

    if(_self.is('input')) {
        _self.addClass('inputClass');
    } 
});

演示

于 2014-06-23T12:30:05.603 回答