2013年3月13日水曜日

jqueryについて

http://ascii.jp/elem/000/000/498/498710/

<script src="//ajax.googleapis.com/ajax/ libs/jquery/1.9.1/jquery.min.js"></script>
をページに追加するとそれだけでどこでもjqueryが使えるようになるとのこと。

要素の指定は
$("セレクター")
で行う。とりあえず
$(要素名)
$(#id名)
$(.クラス名)
の3つの指定の仕方を覚えておくと便利そう。

例:
$("#main img"):idがmainのimg要素
$(p#first):p要素のidがfirst。つまり<p id="first">hogehoge</p>のこと。

要素の変更は
$("セレクター").jQueryの命令
で行う。

例:
$("p#first").html(<strong>変更後</strong>)
で<p id="first">変更前</p>が<p id="first">変更後</p>になる。

$("セレクター").イベント(function(){
イベントの処理
})

例:

$("button").click(function(){
    $("img").attr("src","sea.jpg");
});