I have been working with jQuery recently because we are going to be using it in the 4.1 release of 68 Classifieds. One of the things I couldn’t get my head around was how to pass the id of a database record to a jQuery click function.
For example in regular javascript I had:
function deleteit(id) {
alert(id);
}
<a href="#" onclick="deleteid(1)">Delete</a>
So with a little help I found out how it can be accomplished with jQuery:
$('a.delete').click(function(event) {
event.preventDefault();
var id = this.id.replace('del_', "");
alert(id);
}
<a href="delete.php?act=delete&id=1" id="del_1" class="delete">Delete</a>
I know this isn’t anything revolutionary but it sure had me stumped for a little while. Hopefully this will help someone else just learning jQuery.
