DOMNodeInserted is posible to mark added elements?

242 Views Asked by At

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.

1

There are 1 best solutions below

0
damian On BEST ANSWER

You can get the inserted element with ev.target and check with jQuery's is() method the tag name.

E.g.:

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

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

DEMO