[jQuery] jQuery 링크하기

Narcoker·2023년 5월 25일
0

jQuery

목록 보기
1/3

head 태그 내부에 링크하기

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Document</title>
    <script src="script/jquery-1.12.4.js""></script>
	<script src="script/customs.js"></script>
</head>
<body>
    
</body>


</html>

위 방식을 사용하면 전체 jQuery를 function(){}으로 감싸야한다.

아직 body 태그가 실행되기 전이므로 요소들을 불러올 수가 없다.
function()으로 감싸게되면 html을 읽고 나서 해당 script가 실행된다.

body 태그 내부 최하단에 링크하기

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Document</title>
</head>
<body>
    ...
  	<script src="script/jquery-1.12.4.js""></script>
	<script src="script/customs.js"></script>
</body>


</html>

위 방식을 사용하면 function() {} 으로 감싸지 않아도 된다.

html을 읽어오고나서 실행되기 때문에 문제가 일어나지 않는다.
계층 구조를 줄일 수 있으니 일반적으로 이 구조를 사용한다.

jquery-1.12.4.js

오픈소스 파일이다.
위 파일을 커스텀 파일보다 먼저 링크해야 한다.

<script src="script/jquery-1.12.4.js""></script>
<script src="script/customs.js"></script>
profile
열정, 끈기, 집념의 Frontend Developer

0개의 댓글