I’ve got a fairly straight forward question. Why can’t I use $('a.view').attr('id') (Ref //1 in code) in my click function? I tried it and it failed to work but this.id works. I guess I primarily want to know the difference in the context of the code below:
displayRecord.php (The following link calls the click function):
echo '<td><a href="#" style="text-decoration: none;" id="'.$data['id'].'" class="view" ><input type="button" value="View" /></a></td>';
editTicket.php:
$('a.view').click(
function(e)
{
//1
var ticket_id = this.id;
dlg.load('displayRecord.php?id='+this.id, function(){
var escalationValue = '';
$.post('escalateValue.php',{post_ticket_id:ticket_id},
function(data) {
if (data == 'No'){
showCount();
}
});
dlg.dialog('open');
});
});
$('a.view').attr('id')can match multiple elements, if you have multiple anchors with aviewclass, so you will not necessarily get the clicked element if you use it within aclickevent.this.idrefers only to the element that was clicked and would also be the fastest way, but to demonstrate you could also do: