Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting values of elements inside a div tag

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?

like image 351
Manoj Sreekumar Avatar asked Dec 09 '22 15:12

Manoj Sreekumar


1 Answers

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.
});
like image 156
Adil Avatar answered Dec 26 '22 22:12

Adil