I'm attempting to use .text() on multiple (unknown number of) elements on a page.
Consider:
<div class="myClass">element1</div>
<div class="myClass">element2</div>
<div class="myClass">element3</div>
and
$(document).ready(function(){
$( ".myClass" ).click(function() {
var text = $('.myClass').text()
alert(text)
});
});
The problem is, the .text()
will return all the elements at the same time (in this example: "element1element2element3"
).
I'd need to return only the text within the clicked class, for example: click on element2
, it returns "element2"
as .text()
.