I thought this would be easy but I'm stuck and can't find a solution. I have two divs, both same class. The difference is the content inside each one. I'm trying to get the text and values from each but the output is from both of them. I have an image and when it's clicked, I want to get the value from THIS div where the image is located. Here's my code:
<div class="mainSelect">
<h1>I am Title</h1><br>
<a href="javascript:void(0);" class="clickme"><img class="pic" src="img/img.png"/></a>
</div>
<div class="mainSelect">
<h1>I am Second Title</h1><br>
<a href="javascript:void(0);" class="clickme"><img class="pic" src="img/img.png"/></a>
</div>
And in javascript:
$(document).ready(function(){
$(".clickme").click(function(){
var t = $("h1").text();
alert (t);
});
});
When I do it this way, I get "I am Title I am Second Title". Is there a global way to only display the title of the div where the image was clicked?