I'm new to js/jQuery and found a couple of posts that already helped me a lot with what I'm trying to accomplish. But I'm stuck on this particular problem.
What I want to do is that when I click on the box with the class ".moreInfo", jQuery should find the closest element with the class ".make-3D" and return the id of it. The background is that I have several divs with ".make-3D" including the ".moreInfo" and I want to save the make-3D-ID in a variable that I then hand over to a function so that I can use one trigger event for all .moreInfo-classes. But, I always get an "id is not defined" error.
Here is my basic code (I tried it also with $(this) instead of $(event.target) but from what I read I figured event.target would be the better choice?):
jQuery
$(".moreInfo").click(function () {
var card = $(event.target).closest(".make-3D").attr(id);
flipToBack(card);
});
html
<div id="test" class="make-3D">
<div class="tile">
<div class="front">
<div class="head">
</div>
<div class="location">
</div>
<div class="picContainer">
</div>
<div class="moreInfo">
<b>More Info!</b>
</div>
</div>
<div class="back">
</div>
</div>
</div>