0

I have a javascript function

<script>
    $(document).ready(function(){
        $('.paper_img').click(function(){

            console.log("hello")

            return false;
        });
    });
</script>

how can I access the element which triggered this function? thanks carl

carl
  • 4,216
  • 9
  • 55
  • 103

2 Answers2

0

The this keyword will give you access to the invoker.

Frank V
  • 25,141
  • 34
  • 106
  • 144
0

$(document).ready(function() {
  $('.paper_img').click(function() {
    $('div').html($(this).attr('id') + ' was clicked!');    
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="button_1" class="paper_img">Click me!</button>
<button id="button_2" class="paper_img">Click me!</button>
<button id="button_3" class="paper_img">Click me!</button>
<button id="button_4" class="paper_img">Click me!</button>
<div></div>
Aswin Ramakrishnan
  • 3,195
  • 2
  • 41
  • 65