【jQuery】セレクタで複数の要素を指定する方法(and, or)





Warning: Undefined array key 2 in /var/www/html/wp-content/themes/jstork_custom/functions.php on line 35

and(かつ)の要素を指定

$('.sample-1 .sample-2').on('hover', function(){
....

例えば、sample-1sample-2というクラスを両方持っている要素をセレクタで指定する場合は、セレクタ内のクラス名を半角空白で区切って記載します。

or(または)の要素を指定

$('.sample-1, .sample-2').on('hover', function(){
...

次に、sample-1またはsample-2のどちらかをクラスとして持っている要素をセレクタで指定する場合は、セレクタ内のクラスをカンマで区切って記載します。