Can you have multiple $(document).ready(function(){ … }); sections?

前端 未结 11 1452
庸人自扰
庸人自扰 2020-11-22 13:21

If I have a lot of functions on startup do they all have to be under one single:

$(document).ready(function() {

or can I have multiple such

11条回答
  •  时光说笑
    2020-11-22 13:28

    Yes you can.

    Multiple document ready sections are particularly useful if you have other modules haging off the same page that use it. With the old window.onload=func declaration, every time you specified a function to be called, it replaced the old.

    Now all functions specified are queued/stacked (can someone confirm?) regardless of which document ready section they are specified in.

提交回复
热议问题