how to get jquery anchor href value

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.

Answer

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/

Leave a Reply

Your email address will not be published. Required fields are marked *