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

前端 未结 11 1383
庸人自扰
庸人自扰 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:35

    You can use multiple. But you can also use multiple functions inside one document.ready as well:

    $(document).ready(function() {
        // Jquery
        $('.hide').hide();
        $('.test').each(function() {
           $(this).fadeIn();
        });
    
        // Reqular JS
        function test(word) {
           alert(word);
        }
        test('hello!');
    });
    

提交回复
热议问题