サンプル
サンプル1
divがクリックされた場合に、以下のルールでメッセージを表示。
要素が最初の子要素である → "It's the first div"
blueもしくはredというクラスを持っている → "It's a blue or red div"
"Peter"という文字列を含む → "It's Peter!"
上記以外 → "It's nothing special"
<div></div>
<div class="blue"></div>
<div></div>
<div class="red"></div>
<div><br/><span>Peter</span></div>
<div class="blue"></div>
<p> </p>
$("div").one('click', function () {
if ($(this).is(":first-child")) {
$("p").text("It's the first div.");
} else if ($(this).is(".blue,.red")) {
$("p").text("It's a blue or red div.");
} else if ($(this).is(":contains('Peter')")) {
$("p").text("It's Peter!");
} else {
$("p").html("It's nothing <em>special</em>.");
}
$("p").hide().slideDown("slow");
$(this).css({"border-style": "inset", cursor:"default"});
});
[
フレーム]