$(document).ready() or $(function()) — Which to use?

后端 未结 4 534
后悔当初
后悔当初 2021-01-17 07:59

I saw there is an answered question about whether there is a difference between using $(document).ready(function(){}) and $(function(){}) (there is

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 08:55

    I use $(document).ready(function(){}); despite the additional typing. I just prefer having that in my code to remind me exactly when the code is going to run, and for the ability to search for 'ready' to find those sections. It's the same functionality, and I normally take shortcuts, but in this case I don't.

提交回复
热议问题