jQuery:
$(document).ready(function() {
$("a.change_status").click(function(){
var status_id = $("a").val();
alert(status_id);
return false;
});
});
HTML:
<a href="?status=5" class="change_status">Aminul</a><br/>
<a href="?status=25" class="change_status">Arif</a><br/>
<a href="?status=15" class="change_status">Sharif</a><br/>
I need status_id
and for some reason my anchor tag is dynamic. I can't use id or make class name dynamic. I think, I need to use $this
to get my value.
The only way to pass data with an anchor tag is to put them in the query string. If you have a lot of data and don't want it to appear in the address window, why do you want to use an anchor tag? You could always submit a form from the onclick event of an anchor tag.
Answer: Use the jQuery . attr() Method You can use the jQuery . attr() method to dynamically set or change the value of href attribute of a link or anchor tag. This method can also be used to get the value of any attribute.
We can remove the href by: Setting an empty href – ELEMENT. href = "" Or removing it entirely – ELEMENT.
$('a').attr('href');
should do the trick
This one is simple :
$(document).ready(function() {
$("a.change_status").click(function(){
var status_id = $(this).attr('href').split('=');
alert(status_id[1]);
return false;
});
});
http://jsfiddle.net/NmzRV/
var status_id= $(this).attr("href").match(/status=([0-9]+)/)[1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With