본문 바로가기
💻 하나씩 차곡차곡/Front-end

[javascript] $(document).ready vs $(window).onload (실행)

by 뚜루리 2022. 7. 6.
728x90
320x100
$(document).ready(function(){
});

$(window).onload(function(){
});

[오늘의 궁금증]
ready 와 onload 의 차이점은 무엇일까?
뭐가 더 먼저 실행될까?

 

호출시점

  • $(document).ready  호출시점 : DOM Tree 생성 완료 후
  • $(window).onload 호출시점 : 모든 페이지 구성요소 페인팅 완료 

 

실행 우선순위

ready() -> .onload()

 

$(document).ready()

  • 중복 사용 가능. 
  • $(function(){});과 같음

 

$(window).onload() 

  • 한페이지에 하나만 사용가능.
  • 중복사용 되었다면 가장 마지막 것만 호출됨. 

출처 - https://hahahoho5915.tistory.com/28

 

jQuery .ready() vs .onload() 특징 및 차이

개요 > jQuery를 이용한 뷰단 event 함수 구현 중 비슷하지만 다른 두 jQuery 함수에 대한 궁금증 // 비슷하지만 다른 2개의 소스의 차이점이 무엇인가?? $(document).ready(function(){ alert('hi - ready'); })..

hahahoho5915.tistory.com

 

728x90
320x100