Owlcarousel2: Owl carousel 2 cloned item click events not firing

Created on 31 Jul 2015  路  5Comments  路  Source: OwlCarousel2/OwlCarousel2

I'm currently using Owl Carousel 2.0.0-beta.2.4 in development to keep the carousel centered and loop the items which works nicely.

For some reason the cloned items that Owl generates when setting loop: true doesn't seem to fire on click. You will see in the example I've put together below that every other item alerts the click when fired but if the item has been cloned it doesn't seem to register the click event.

https://jsfiddle.net/5fyhtm51/

Most helpful comment

Hi, @ui-matt

  1. You could still use event delegation to make all your clicks work fine with some kind of micro-optimization by reducing memory for every click handler that you attach in your example.
$('#multiple-carousel').on('click', '.item', function () {
    alert("click");
});
  1. There is a little time gap in your example, when new items are not cloned yet, but your click handler is already applied to existing items. That's another reason to use event delegation.

All 5 comments

Hi, @ui-matt

  1. You could still use event delegation to make all your clicks work fine with some kind of micro-optimization by reducing memory for every click handler that you attach in your example.
$('#multiple-carousel').on('click', '.item', function () {
    alert("click");
});
  1. There is a little time gap in your example, when new items are not cloned yet, but your click handler is already applied to existing items. That's another reason to use event delegation.

Ah nice!

Seems to work a treat, thanks for that @dashukin

Is there way to get item index for the clicked item? I woud like to know which item is clicked.

@negativefix Did you ever find how to properly get the index?

Using n = $(this).index(); the index is all over the place, I guess because of the cloned items.

2021 Should fix this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

unite4 picture unite4  路  4Comments

hopea114y picture hopea114y  路  3Comments

shamimsaj picture shamimsaj  路  3Comments

leecollings picture leecollings  路  3Comments

mkraha picture mkraha  路  4Comments