What are the side effects (if any) of multiple $(document).ready() in an HTML page?

后端 未结 3 1368
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 15:04

I am using a web application framework (Symfony 1.3.6), which follows the MVC pattern.

The view layer is comprised of a template decorator. The template file may also in

3条回答
  •  被撕碎了的回忆
    2021-02-20 15:24

    There are no problems with multiple $(document).ready() calls, only a couple of caveats:

    • Reduced readability.
    • Scope: a function/variable/object declared inside one $(document).ready() will not be visible in any others. See this simple demo.

    Also see this previous question on SO:

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

提交回复
热议问题