简体   繁体   中英

jQuery trigger an event when specific element is loaded

I would like to globally catch whenever some element (fe textarea ) is rendered on the page to do something with it. Element could be inserted by AJAX request too.

// This is just an example of functionality I want to achieve
// Not a real code
$(document).on('render', 'textarea', function() {
    $(this).whatEver();
});

I know about document's ajaxComplete method, but I am looking for some more generic way.

Use:

$('#container').on('DOMNodeInserted ', 'textarea', function(){
$(this).whatEver();
})

Or:

$(document).ready(function () {
 //Loaded...
 $('textarea').whatEver();
});

Found the way to do it using livequery plugin which repetitively checks for elements in dom. So I can do following:

$('textarea').livequery(function() { $(this).whatEver(); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM