Netanel Dadon
Netanel Dadon

Reputation: 68

Run Javascript Jquery function on two different classes

i have those classes:

.slider
.sliderlogo

and i have those pieces of codes:

var sc=$(".slider img").size();
$(".slider #"+count).show("slide",{direction:'right'},500);
$(".slider #"+count).delay(5500).hide("slide",{direction:'left'},500);

what's the right way to add the other "slidelogo" class to the JS so it will run on the other class as well?

generaly its like:

(".slider #1,.sliderlogo #1")

bit its not working for the above code lines. thanks in advance.

Upvotes: 1

Views: 85

Answers (3)

Pete Thorne
Pete Thorne

Reputation: 2776

As David says, the id must be unique, so try changing them to

.slider #slider1

and

.sliderlogo #sliderlogo1

etc.

then use:

(".slider #slider"+count+",.sliderlogo #sliderlogo"+count)

Upvotes: 1

Skatox
Skatox

Reputation: 4284

The ID should be unique in the entire document, so i recommend you to use classes instead, something like .item-1, .item-2 and then change the code to:

var sc=$(".slider img").size();
var selector = ".slider .item-" + count + ", .sliderlogo .item-" + count;
$(selector).show("slide",{direction:'right'},500);
$(selector).delay(5500).hide("slide",{direction:'left'},500);

Upvotes: 1

xdumaine
xdumaine

Reputation: 10349

It looks like you might have issues with your markup, as IDs must be unique on the document and cannot begin with a number. If you must use the Ids, try building them as something like 'slider' + count and 'sliderLogo' + count. so that each is unique.

Upvotes: 1

Related Questions