I'm working on a project where I'm displaying a list of images. At each image there is the possibility to the delete the item and to edit.
When a user clicks on "Edit" a modal has to show up with the corresponding data. Now my problem is to get the title and the description of the selected item.
I have searched before on this problem and I know that I have to use the jQuery function "closest" but I haven't been able to get it working.
var thisTitle = $(this).closest(".photo").closest(".item_title").text();
Here you can find my jsFiddle: enter link description here
If you want to use closest
then correct selector would be:
var thisTitle = $(this).closest(".photo-wrapper").find(".item_title").text();
First you need to find closest parent container with class photo-wrapper
(not photo
) and within this container you search for .item_title
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.