I have multiple div tags with different ids on a page with the following property:.
<div class="alert alert-info" id="1">
<p><b><span class="adName">Name</span></b><br>
<span class="ad1">address1</span><br>
<span class="ad2">address2</span><br>
<span class="ad3">address3</span><br>
<span class="adCity">city</span><br>
<span class="adState">state</span><br>
<span class="adPin">pincode</span><br>
Ph no :<span class="adPhone">phone</span><br>
</p>
</div
I want to get the values inside the span tags when a particular div is clicked. How can I idntify the div which is clicked and then get its contents?
You can use find() method in the click event of div.
$('.alert.alert-info').click(function(){
var $this = $(this);
adName = $this.find('.adName').text();
ad2 = $this.find('.ad2').text();
//So you can repeat for remaining elements.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With