jQuery document.ready

前端 未结 5 2039
北恋
北恋 2020-11-28 16:38

I am a little confused with document.ready in jQuery.

When do you define javascript functions inside of $(document).ready() and when do you not?

Is it safe

5条回答
  •  情话喂你
    2020-11-28 17:14

    If you have your scripts at the end of the document, you dont need document.ready.

    example: There is a button and on click of it, you need to show an alert. You can put the bind the click event to button in document.ready. You can write your jquery script at the end of the document or once the element is loaded in the markup.

    Writing everything in document.ready event will make your page slug.

提交回复
热议问题