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.

LJ Wadowski
  • 6,424
  • 11
  • 43
  • 76

1 Answers1

1

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

damian
  • 5,314
  • 5
  • 34
  • 63