Reputation: 27445
I need to get value from a href button. Here I have just developed a code which show all href value. Actually I need to get value from where I click.
here is my code
$(document).ready(function() {
$("a.me").click(function(){
var number = $('a').text();
alert(number);
});
});
Upvotes: 0
Views: 8505
Reputation: 1068
one of the answers above will work or you could use
...
$("a.me").click(function(e){
var number = $(e.target).text();
alert(number);
});
Upvotes: 0
Reputation: 154
In jQuery you can use $(this) to reference the element that was clicked (or otherwise used)
Like so:
$("a.me").click(function(){
var number = $(this).text();
alert(number);
});
Upvotes: 1
Reputation: 218722
$(document).ready(function() {
$("a.me").click(function(){
var target=$(this).attr("href");
alert(target);
});
});
Upvotes: 0
Reputation: 56467
$("a.me").click(function(){
var number = $(this).attr('href');
alert(number);
});
Upvotes: 4
Reputation: 76870
You should do
$(document).ready(function() {
$("a.me").click(function(){
//It's not clear if you want the href attribute or the text() of the <a>
//this gives you the href. if you need the text $(this).text();
var number = this.href;
alert(number);
});
});
Upvotes: 5