본문 바로가기
개발자이야기

[JavaScript]Uncaught ReferenceError: $ is not defined..

by N의 블로그 2023. 6. 26.
728x90
반응형
SMALL

JavaScript 를 사용하다 이런 오류가 발생 했습니다.

 

Uncaught ReferenceError: $ is not defined

 

jQuery 라이브러리를 삽입하지 않고 태그했지 때문에 $기호를 찾을수 없다. 라고 오류를 내고 있습니다.

웹 개발시에 JavaScript 를 쓰게 되면 jQuery 라이브러리를 삽입하지 않은 채 무심코 쓰게 되는 경우가 있는데요.

워낙 jQuery를 많이 사용하기 때문에 까먹게되는거 같습니다.

 

jQuery는 HTML 문서의 요소를 선택하고 조작하기 위한 JavaScript 라이브러리입니다. jQuery는 강력한 선택자와 다양한 기능을 제공하여 웹 개발자들이 JavaScript를 좀 더 쉽게 작성할 수 있게 도와줍니다.

 

jQuery 라이브러리가 삽입되어 있는지 확인하시고 jQuery 라이브러리가 없는 경우

이 오류를 해결하기 위해서 두가지 방법을 사용 할수 있는데

 

1. jQuery 라이브러리를 다운받아 파일로 저장해두고 사용하는 경우

https://jquery.com/download/

 

Download jQuery | jQuery

link Downloading jQuery Compressed and uncompressed copies of jQuery files are available. The uncompressed file is best used during development or debugging; the compressed file saves bandwidth and improves performance in production. You can also download

jquery.com

https://releases.jquery.com/

 

jQuery CDN

The integrity and crossorigin attributes are used for Subresource Integrity (SRI) checking. This allows browsers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice, whenever libr

releases.jquery.com

 

2. 최신 jQuery를 제공해주는 링크 이용

//code.jquery.com/jquery-latest.min.js

<script  src="//code.jquery.com/jquery-latest.min.js"></script>

 

원하는 방식으로 사용하면 되고..

저는 주로 2번째 방식을 사용하는데 링크가 바뀌게 될 경우 경로를 전체적으로 수정해줘야하는 단점이 있습니다.

개발하는 환경에 맞춰 사용하시면 될거같습니다.

이렇게 Uncaught ReferenceError: $ is not defined.. 오류는 간단하게 해결 되었습니다.^^;;

728x90
반응형
LIST