セレクタでカンマを使って異なる要素の OR をとる
次のように、異なる要素に対して同じ操作をするときは、
$('#c1')
.ToolTip({
className: 'tooltip',
position: 'mouse',
delay: 500
});
$('#c2')
.ToolTip({
className: 'tooltip',
position: 'mouse',
delay: 500
});
$('.handle')
.ToolTip({
className: 'tooltip',
position: 'mouse',
delay: 500
});
$('a', '#r')
.ToolTip({
className: 'tooltip',
position: 'mouse',
delay: 500
});
次のように、カンマを使えばよいですね。
$('#c1, #c2, .handle, #r a')
.ToolTip({
className: 'tooltip',
position: 'mouse',
delay: 500
});
カンマが OR と連想しにくい気がしますが、覚えてしまえば JavaScript コードのタイプ数をかなり減らせます。
関連情報
- fixedUI プラグイン
- jTemplates
- Cycle Plugin
- Flash Plugin
- tablesorter
- Interface Elements
-
- Interface Elements の Carousel とフォートラベル API で旅行写真の 3D ギャラリーを作る
- Interface Elements の Imagebox とフォートラベル API で旅行写真のギャラリーを作る
- Interface Elements の Slider で郵便番号を入力してみたが・・・
- Interface Elements の Slider で旅行写真を拡大(または縮小)表示する
- Interface Elements の Tooltips をいろいろな要素で使ってみた
- Interface Elements の Scrollto でページ内リンクをスムースにする
- Interface Elements の Carousel と YouTube Data API で動画のサムネイルを回転表示する
- Selectors
- Events
- DOM Manipulation
- AJAX
- Forms with Functions
- Using with Other Libraries
- Books
-
- Resources
