user3228992
user3228992

Reputation: 1373

Jquery -trigger class only where it is clicked

I'm having multiple divs with same the same class.

<div class="myClass" id="1">content1</div>
<div class="myClass" id="2">content2</div>
<div class="myClass" id="3">content3</div>

When I click the class, I'm having a function that triggers:

$('.myClass').click(function () {
            $('#1').note({ focus: true });
        });

the problem is: How can I trigger the class only where it's clicked? If I'm using the solution above, <div class="myClass" id="1">content1</div> triggers when I click on any of the divs with class="myClass"

And If I'm using this below, then I need a function for each div:

$('#1').click(function () {
            $('#1').note({ focus: true });
        });

//Thanks

Upvotes: 0

Views: 22

Answers (1)

Rob Schmuecker
Rob Schmuecker

Reputation: 8954

Use the this keyword

$('.myClass').click(function () {
            $(this).note({ focus: true });
        });

Upvotes: 3

Related Questions