I am developing an application using HTML and JQuery (and AngularJS). I am new to using JQuery and have a question. Let's assume I have this HTML file:
<div class="my_class">1</div>
<p ng-click="my_method()">MY FIRST PARAGRAPH</p>
<div class="my_class">2</div>
<p ng-click="my_method()">MY SECOND PARAGRAPH</p>
<div class="my_class">3</div>
<p ng-click="my_method()">MY THIRD PARAGRAPH</p>
<div class="my_class">4</div>
<p ng-click="my_method()">MY FOURTH PARAGRAPH</p>
<div class="another_class">something in here..</div>
<div class="my_class">5</div>
If in the my_method()
method I want to use JQuery code to dynamically change the style of a SINGLE <div>
element associated with the my_class
class I don't know how to do it.
I know that the following code:
$(".my_class")
will select all the elements associated with the my_class
class. But how do I, for example, select exactly <div class = "my_class"> 4 </div>
if I click on <p ng-click="my_method()">MY FOURTH PARAGRAPH</p>
(In this case the div I'm interested in is the closest to the top of the point where I clicked)?