0
I am applying image attributes and names via Jquery through an array of images and names. The image below illustrates the images of the loaded array.
When I click I display the name of the image contained in the array. Below the image illustrates what happens when the event is held click, the names are displayed below the images, in the case ai only two images were clicked.
I have to count the clicks too. However I do not know how to perform the same event in the code below:
My html code looks like this:
<div class="col-md-3">
<figure class="catImag"><img src=""></figure>
<span class="count"></span> onde vai o contador
</div>
And this is my jQuery with event click.
const catsImages = ['cat01.jpg', 'cat02.jpg', 'cat03.jpg', 'cat04.jpg', 'cat05.jpg'];
const catsName = ['Cat KiKI', 'Cat Edi', 'Cat Didi', 'Cat Kely', 'Cat Vivi'];
let image = [...catsImages];
let name = [...catsName];
console.log(image);
console.log(name);
let count = 0;//Variavel contador
$.each($('.catImag img'), function(index) {
$(this).attr({
src: image[index],
alt: name[index]
});
}); //Update Cat cria os atributos para receber a imagem
$.each($('figure'), function(index, el) {
$(this).one('click', function(event) {
/* Act on the event */
$(this).append('<figcaption>' + name[index] + '</figcaption>');
});
});// update click name, exibe o nome do cat clicado
I don’t understand the use of this line:
let $span = $('img').append('<span>' + count + '</span>');
... u want to make an append inside an image? An image is a closed element and does not accept append. Could explain better?– Sam
That line I forgot to take was a test I was performing. Ignore it.
– Wemerson Nino
I removed the answer. You have to adjust the question with the correct code. Noa comments you are taking and adding codes. You just have to edit the question with what you want and the correct code.
– Sam
OK I’ll rephrase the question here.
– Wemerson Nino