0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[jQuery] を使う準備をする

Last updated at Posted at 2021-01-25

CDNを利用してjQueryを読み込む

今回はGoogleが提供しているCDNを読み込みます。
Googleが提供しているCDN を開き、利用したいjQUeryのバージョンのコードをコピーしてHTMLの head 内に貼り付けます。
(今回は v3.X の最新版を利用してみました。)

jQueryのコードを記述するファイルを読み込む

jQueryは、.js形式のファイルにコードを書きます。 HTMLファイルで、 <script src="ファイルのURL"></script> を追記します。 <script> はbody閉じタグ直前に書くことで、WEBページの表示速度をより早めることが出来ます。
今回ファイルのURLは script.js にしました。
ファイルのURLを間違えないように注意しましょう。

html
<body>

  <script src="script.js"></script>
</body>

js形式のファイルにコードを書いていく

jQueryはHTMLの中身を操作するので、HTMLの読み込みをしてからjQueryの操作を開始します。 そのためにreadyイベントを使用し、 $(document).ready() の中身にjQueryの処理を書いていきます。 この構文の省略形は、 $(function(){ }); と書くので今回は省略形で書いていきます。

script.js
$(function(){
  処理
});

処理の中に実行したい処理を書いていきましょう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?