来自锚标签的ID [已关闭]

Is this possible with php and javascript? Can I echo my anchor tag ID and retrieve it with jquery onclick event? Echo " a href = 'example.con' id=' ".$row['userid']."' example /a"; now in jquery/javascript I say something like onclick of the anchor tag I get the id of whatever the row is. If not can someone give me another solution.

This should do what you're looking for:

$('#myLinkId').click(function() {
    var linkId;
    linkId = $(this).prop('id');
    alert(linkId);
});

This code: .prop('id'); is specifically what gets the link's ID.

Non jQuery alternative:

function getId(e){
    //IE e.srcElement.href);
    //Other e.target.href);
    alert(e.srcElement.id);
}

Add the onclick="getId(event)" to your anchor.

For crossbrowser implementation you can see this question:

How can I make event.srcElement work in Firefox and what does it mean?