Search code examples
jqueryhandlerjquery-events

Will $(document).ready(function(){ ... }) clean all previous event handlers registered with document ready?


I have a doubt about the .ready() function in jQuery. In particular, consider a situation where someone has bound some handler to the document ready event, and I execute

$(document).ready(function(){ /* my code here */ })

Will this overwrite the previously registered handler, or only add a new one (mine) to the event?


Solution

  • Agreed. You can use that function as many times as you like. Here's the JQuery documentation.

    http://docs.jquery.com/Tutorials:Multiple_$(document).ready()

    All the functions, $(document).ready(), $(window).load() along with binds like click all get added to the stack. This way you can use the $(document).ready on all your javaascript files.