jQuery๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

jQuery ๋Š” ๋น ๋ฅด๊ณ  ์ •ํ™•ํ•œ JavaScript Library ์ž…๋‹ˆ๋‹ค. John Resig์ด๋ผ๋Š” ์‚ฌ๋žŒ์ด 2006๋…„์— ๋งŒ๋“ค์—ˆ๋‹ค๊ณ  ํ•˜๋„ค์š”. Write less, do more. ์ด๊ฒŒ jQuery๊ฐ€ ํƒ„์ƒํ•œ ์ด์œ ์ž…๋‹ˆ๋‹ค. ์ ์€์ฝ”๋“œ๋กœ ๋งŽ์€ ์ผ์„ ํ•˜๋Š” ๊ฒƒ. 

jQuery ๋Š” HTML ๋ฌธ์„œ traversing, event handling, animating, and Ajax interactions ์„ ๋‹จ์ˆœํ™” ์‹œ์ผœ์ค๋‹ˆ๋‹ค.

jQuery์˜ ํŠน์ง•์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • DOM ์กฐ์ž‘: Sizzle์ด๋ผ๋Š” selector์—”์ง„์„ ์ด์šฉํ•ด์„œ DOM ์š”์†Œ๋ฅผ ์„ ํƒํ•˜๊ฑฐ๋‚˜, ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜, ์š”์†Œ์˜ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•˜๋Š” ์ž‘์—…์„ ์šฉ์ดํ•˜๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค. 

  • Event handling: HTML์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค. 

  • AJAX ์ง€์› 

  • ์• ๋‹ˆ๋ฉ”์ด์…˜ : ์ƒ๋‹นํžˆ ๋งŽ์€ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • ๊ฐ€๋ณ๋‹ค : 19KB ์ •๋„ ๋ฐ–์— ์•ˆ๋˜๋Š” ๋งค์šฐ ๊ฐ€๋ฒผ์šด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ž…๋‹ˆ๋‹ค. ( Minified and gzipped ).

  • ๋‹ค์–‘ํ•œ ๋ธŒ๋ผ์šฐ์ € ์ง€์› : IE 6.0+, FF 2.0+, Safari 3.0+, Chrome and Opera 9.0+

  • ์ตœ์‹  ๊ธฐ์ˆ  ์ง€์› : CSS3 selectors ์™€ basic XPath ๋ฌธ๋ฒ•์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

jQuery ์„ค์น˜ํ•˜๊ธฐ

jQuery ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์€ ์–ด๋ ต์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 

  1. ์ตœ์‹ ๋ฒ„์ „ ๋‹ค์šด๋กœ๋“œํ•˜๊ธฐ : download jQuery  

  2. ๋‹ค์šด๋กœ๋“œํ•œ ์ตœ์‹ ๋ฒ„์ „์˜ jquery-x.y.z.min.js ํŒŒ์ผ์„ ํ”„๋กœ์ ํŠธ ๊ฒฝ๋กœ ๋‚ด์— ๋„ฃ์–ด์ฃผ์„ธ์š”, e.g. /jquery.

ํŒŒ์ผ๋ช…์— min.js๋กœ ๋๋‚˜๋Š” ๋ฒ„์ „์€ ์ตœ์†Œํ™”๋œ ๋ฒ„์ „์œผ๋กœ ๋ถˆํ•„์š”ํ•œ ๋นˆ ์ค„์ด๋‚˜ ๋‹จ์–ด๋ฅผ ์ œ์™ธํ•œ ๋ฒ„์ „์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

 

jQuery ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉํ•˜๊ธฐ

 jquery ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ includeํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

<html>
<head>
<title>The jQuery Example</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript">
      // you can add our javascript code here 
   </script>   
</head>
<body>
........
</body>
</html>

jQuery ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ•จ์ˆ˜ ํ˜ธ์ถœํ•˜๊ธฐ

As almost everything we do when using jQuery reads or manipulates the document object model (DOM), we need to make sure that we start adding events etc. as soon as the DOM is ready.

If you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded.

To do this, we register a ready event for the document as follows:

$(document).ready(function() {
   // do stuff when DOM is ready
 });

To call upon any jQuery library function, use HTML script tags as shown below:

<html>
<head>
<title>The jQuery Example</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   
   <script type="text/javascript" language="javascript">
   // <![CDATA[
   $(document).ready(function() {
      $("div").click(function() {
        alert("Hello world!");
      });
   });
   // ]]>
   </script>

</head>
<body>
<div id="newdiv">
Click on this to see a dialogue box.
</div>
</body>
</html>

 

 

์‚ฌ์šฉ์ž ์ •์˜ ์Šคํฌ๋ฆฝํŠธ ์‚ฌ์šฉํ•˜๊ธฐ

custom.js ํŒŒ์ผ์— ๋‚ด๊ฐ€ ์ •์˜ํ•œ ๊ธฐ๋Šฅ์„ ๋”ฐ๋กœ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

/* Filename: custom.js */
$(document).ready(function() {
  $("div").click(function() {
 alert("Hello world!");
  });
});

๋‹ค๋ฅธ ํŽ˜์ด์ง€์—์„œ custom.js ํŒŒ์ผ๋‚ด์— ์ •์˜๋œ ๊ธฐ๋Šฅ์„ ์‹คํ–‰ํ•˜๊ณ ์ž ํ• ๋•Œ์—๋Š” ์ด ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค

<html>
<head>
<title>The jQuery Example</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" 
   src="/jquery/custom.js"></script>
</head>
<body>
<div id="newdiv">
Click on this to see a dialogue box.
</div>
</body>
</html>

 

๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋™์‹œ ์‚ฌ์šฉํ•˜๊ธฐ:

jQuery ๋ฅผ ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์ถฉ๋Œ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. $ ๊ธฐํ˜ธ๋ฅผ ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.   

 

 $.noConflict() ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด $ ๋ณ€์ˆ˜๋ฅผ ๋จผ์ € importํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์šฐ์„ ๊ถŒ์„ ๋„˜๊ธฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. jQuery์—์„œ $๋Š” ๋‹จ์ง€ jQuery์˜ alias์ผ ๋ฟ์ด๋ฏ€๋กœ $๋ฅผ ์“ฐ์ง€ ์•Š์•„๋„ ์ „ํ˜€ ๋ฌธ์ œ๋  ๊ฒƒ์ด ์—†์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ๋ฒ•์„ ํ•œ๋ฒˆ ๋ณด์‹œ์ฃ . 

// Import other library
// Import jQuery
$.noConflict();
// Code that uses other library's $ can follow here.

์ด ๋ฐฉ๋ฒ•์€ ํŠนํžˆ .ready() ๋ฉ”์†Œ๋“œ์˜ ๊ธฐ๋Šฅ๊ณผ ์“ฐ์ผ๋•Œ ๊ฐ•๋ ฅํ•˜๋‹ค๊ณ  ํ•˜๋„ค์š”. jQuery์˜ $๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด์ฃ .  

์‚ฌ์šฉ๋ฒ•์„ ํ•œ๋ฒˆ ๋ณด์‹ค๊นŒ์š”? 

// Import other library
// Import jQuery
$.noConflict();
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
});
// Code that uses other library's $ can follow here.
DOM Element

 

 

 

 

Reference : http://www.tutorialspoint.com/jquery/jquery-overview.htm