권형&오형의 일상

[권형] 04. jQuery 키워드 치환 본문

개발/Jquery

[권형] 04. jQuery 키워드 치환

권형&오형 2017. 9. 26. 14:51
jQuery 키워드 치환
 
1
2
3
$(document).ready(function(){
    //실행할 코드
});


1
2
$("p")
jQuery("p")

 

$와 jQuery를 구분해서 사용하는 경우
$ 문자 치환의 경우 jQuery 라이브러리에서만 사용되지 않는다. 
다른 자바스크립트 라이브러리(Prototype 등)에서도 사용되므로 두 개 이상의 자바스크립트 라이브러리를 사용한다면 라이브러리 간에 충돌이 생길 수있다.
→ 이 경우에는 $ 치환을 해서는 안된다. 

일반적으로는 jQuery 라이브러리 하나만 사용하기 때문에 $문자를 사용하면 된다. 

 



$(document).ready()의 단축 형태

1
2
3
$(function(){
    //실행할 코드
});



1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE HTML>
<html>
    <head>
        <title>Simple</title>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="index.css" />
        <script src="index.js"></script>
    </head>
    <body></body>
</html>
cs
 
1
2
3
$(function(){
    alert("Hello");
});
cs


Comments