Sorry for this silly question, newbie here.
I’m trying to do a testing and I want to insert the element name and ALT text values into var tagged ={} object.
var $img = $(‘#gallery img’);
var tagged = {};
$img.each(function(el, val) {
tagged[el] = val <-----this is the part where I'm lost
})
console.log("tagged result : ", tagged);
My goal is to have this result like: {img, picture1, img, picture2}
2
Answers
You intend to create an object of key-value pairs, where the value is the image element. It’s unclear to me what the keys should be, but basically you can use any key you want as you have a solid idea of what the end-result you want to achieve is. Your original code created an index for the images and that index was being used as the key. In my example the images have a title each and I use it as the key.
Images were taken from here: https://www.cntraveler.com/gallery/the-most-beautiful-forests-in-the-world
It is not completely clear what your ask. Here is a suggestion