Reputation: 139
I have these anchors generated by php script:
<a href="#" class="remFile"> Leaf </a>
<a href="#" class="remFile"> Flower </a>
<a href="#" class="remFile"> Branches </a>
<a href="#" class="remFile"> Seeds </a>
I need to click on e.g. Flower and alert "flower";
I used jquery:
alert( $(".remFile").html()); // output 1st item "Leaf" on any anchor clicked
I also tried:
alert( $(".remFile").text()); // output all values on any anchor clicked
If it is not possible, can you please suggest some other solutions? like using < li > ?
Upvotes: 0
Views: 80
Reputation: 2798
use this -
$('.remFile').click(function(e) {
e.preventDefault(); // or return false;
alert($(this).html());
});
Live demo : click here
Upvotes: 1
Reputation: 1087
As I can understand you want to do this:
$(".remFile").click(function(){
alert($(this).html());
});
Upvotes: 0
Reputation: 25527
try
$(".remFile").click(function(){ alert($(this).html())});
Upvotes: 1
Reputation: 9947
just use this to refer to current anchor
alert($(this).text();
$('a').click(function(){
alert($(this).text());
});
Upvotes: 1