jQuery_02

※基本の基本は→http://www38.atwiki.jp/soyjoynice/pages/77.html

- - -
【メソッドとパラメータ】
$("p").css("color", "red"); の
   .css("color", "red") の部分。
※パラメータは、場合によっては無くてもOK。

- - -
【パラメータが増えるとこうなる_css()】
1)
$("p").css("color");

<p>内のテキストの色を取得

2)
$("p").css("color", "red");

<p>内のテキストの色を 赤 に変更

3)
$("p").css({"color": "red", "text-decoration": "none"});
<p>内のテキストを
 1)色を 赤 に変更
 2)文字装飾は なし

- - -
【パラメータが増えるとこうなる_width()】
1)
$("img").width();

<img>の横幅を取得

2)
$("img").width("150px");

<img>の横幅を 150px にする

- - -
【その他のメソッド_addClass()…クラスを追加】
$("#navi a").addClass("current");

id名が「navi」の<a>に、「current」というクラス名を追加。

- - -
【その他のメソッド_attr()…属性を追加】
$("a").attr("target", "_blank");

<a>に「target="_blank"」を追加(別窓で開く)

* * *
参考:
http://webdesignrecipes.com/jquery-beginners-guide-for-web-design/
最終更新:2011年11月21日 17:19