jQuery :notと:first

2009年08月26日(水)

やったのに忘れそうなのでメモします。
table.sampleの最初の行以外をホバーした時に
クラスを適用します。

$(“table.sample tr:not(:first)”).hover(
function(){
$(this).addClass(“selected”);
},function(){
$(this).removeClass(“selected”);
}
);

jQuery セレクタで:not()を使う事に

2009年08月05日(水)

カレンダーで、未来のtdには.future、データが見つからないものには.notfound
というクラスを適用していましたが
JQueryにてbackground-imageを変える際、このクラスには適用したくなかったので。
普通です。

$("#calendar td:not(.notfound,.future)").hover(
 function(){$(this).css("background-image","url(images/hover.png)"},
 function(){$(this).css("background-image","url(images/normal.png)"}
);

さらに空白のタグも選びたくない場合

$("#calendar td:not(.notfound,.future,:empty)")

としたら出来ました。

:not()の中に:emptyがあって、不思議です。