I am developing an image gallery with cordova, I access the container directory, I read its content and I show the images in a section, generated with javascript, in this way
function success(entries) {
var i;
for (i=0; i<entries.length; i++) {
//alert(entries[i].name);
var rute = entries[i].nativeURL;
document.getElementById("photosContent").innerHTML += "<div class='photos' ><img src='"+rute+"' class='rounded test'></div>"
}
}
I get the src (because there I have the route to be able to use it with the open plugin) when clicking on a class test element, like this
$(".test").click(function() {
let tDIVP = $(this).attr('src');
//console.log(tDIVP);
console.log(tDIVP);
cordova.plugins.disusered.open(tDIVP, successLP, errorLP);
});
I use the console to know if it is receiving the event, but it does not recognize it, it does not perform the action when clicked.
It does not send any errors, sometimes it accepts the click, so there is no syntax or logic error, it just does not always recognize the event.
Any solution.
Your problem is the way you capture the event
$(".test").click(function() {//CODE})
, this form is used for elements that already exist on the page (they were loaded initially), when you capture events of elements that you create later (when the page is already loaded) you have to use$('body').on('click','.test',function(){//CODE})
Your code would be as follows: