html - jquery identify which div is clicked -


i have 4 divs in 1 main div. no div has id. want identify div clicked jquery.

below html code have.

    <div class="body">         <div class="summery-item-widget">details 1</div>         <div class="summery-item-widget">details 2</div>         <div class="summery-item-widget">details 3</div>         <div class="summery-item-widget">details 4</div>     </div> 

thank in advance.

you can use this keyword in event handler reference clicked element:

$('.summery-item-widget').click(function() {    var text = $(this).text();    console.log(text);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="body">    <div class="summery-item-widget">details 1</div>    <div class="summery-item-widget">details 2</div>    <div class="summery-item-widget">details 3</div>    <div class="summery-item-widget">details 4</div>  </div>


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -