How can I define 2 classes in one var?

I have a problem with defining a second class in one Var

Here is the code: http://jsfiddle.net/2DuQc/

How can I make this work beautiful?

It is written in jQuery!

var animateEye = $('.rightEye, .leftEye'); 

does not work!

+4
source share
2 answers

In fact, your code will not work because you rewrite your variabile with only one selector .leftEye, therefore .rightEyeit will not be attached to it.

You can use a multiple selector than loop through the result using jQuery eachand apply the current yuor code.

, , find .

:

$('.rightEye, .leftEye').each(function () {
    var animateEye = $(this);
    var eyes = animateEye.find(".Eye");

: http://jsfiddle.net/IrvinDominin/rU9E2/

+4
var animateEye = $('.rightEye, .leftEye');

, , , , animateEye.offset(), ? .

:

var animateEye = $('.rightEye');
var  eyes = $(".Eye");
var animateEye = $('.leftEye');

, , .leftEye.

? rightEye leftEye :

var eyes = $('.rightEye, .leftEye');
for(var i = 0; i < eyes.length; i++) {
    var animateEye = eyes[i];
}
+3

Source: https://habr.com/ru/post/1543555/


All Articles