Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: both .ready() and .ajaxComplete

Tags:

jquery

I want some part of my JS to initialize when document is ready OR when ajax query completed
Something like this:

if ($(document).ready() or $(document).ajaxComplete()) {
  // do something
}

Is it possible to write such a a condition?
And how do I make it right?

like image 559
c00p3r.web Avatar asked Oct 09 '13 08:10

c00p3r.web


1 Answers

u can use bind Function

 $(document).bind('ready ajaxComplete', function(){
  // Your code here
 })

Though I agree with Felix in comments that ready function is a separate function mostly used to carry actions only when entire document is loaded

like image 130
Jigar Jain Avatar answered Nov 02 '22 23:11

Jigar Jain