jQuery ライブラリは、単純なマークアップ行を使用して Web ページに追加できます。
jQuery は JavaScript ライブラリです。
jQuery ライブラリには次の機能が含まれています。
jQuery ライブラリは、すべての jQuery 関数を含む JavaScript ファイル内に存在します。
JQuery は、次のマークアップを使用して Web ページに追加できます。
<head> <script type="text/javascript" src="jquery.js"></script> </head>
<script> タグはページの <head> セクションに配置する必要があることに注意してください。
次の例は、HTML ドキュメント内のすべての <p> 要素を非表示にする、jQuery の hide() 関数を示しています。
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button type="button">Click me</button>
</body>
</html>
ダウンロードできる jQuery のバージョンは 2 つあります。1 つは縮小版、もう 1 つは非圧縮 (デバッグまたは読み取り用) です。
両方のバージョンは、jQuery.com からダウンロードできます。
Google と Microsoft は jQuery を非常によくサポートしています。
コンピュータで jQuery ライブラリをホストしたくない場合は、Google または Microsoft から CDN jQuery コア ファイルをロードできます。
<head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs /jquery/1.4.0/jquery.min.js"></script> </head>
<head> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery /jquery-1.4.min.js"></script> </head>