1

I would like to globally catch whenever some element (f.e. 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.

0

2 Answers 2

1

Use:

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

Or:

$(document).ready(function () {
 //Loaded...
 $('textarea').whatEver();
});
Sign up to request clarification or add additional context in comments.

1 Comment

DOMNodeInserted detects only direct children of the container, therefore it does not detect nested textareas. $(document).ready does not work for textareas loaded by ajax.
0

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(); });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.