I am trying to create a slideshow plugin, however, when I try to navigate to the left and right the listener's that are attached to the controls aren't updating
$.fn.imageOverlay = function () {
return this.each(function () {
var $this = $(this);
$this.click(function () {
//load paramters and stuff
$.ajax({
//stuff
success: function(data) {
loadOverlay(data);
}
});
});
var loadOverlay = function() {
jQuery(document).on('click', '.rightCtrl', function () {
var id = $(this).data('id');
console.log(id);
$.ajax({
type: "POST",
url: domain + "loadajax/get_photo_overlay",
data: { id: id, type: params.type, criteria: params.criteria },
dataType: 'json',
success: function (data) {
setData(data);
}
});
});
};
var setData = function (data) {
$('.rightCtrl').attr('data-id', data.controls.right);
};
});
})(jQuery);
When I click on the div "rightCtrl" it fires but an old data-id is being used. While inspecting the html markup the attribute is updating, but the new values aren't being passed. The issues lies within the function loadOverlay:
jQuery(document).on('click', '.rightCtrl', function () {
var id = $(this).data('id'); //this is an outdated value
}