How can I pass custom data to the jQuery event handler, specifically from the $(this) element? In HTML5, I probably can legally write:
<a class="delete" href="delete.php?id=5" data-id="5">delete</a>
although I still feel a bit awkard about that. How about prior to that?
$(".delete").click(function() {
return confirm("Do you really want to delete " + $(this).attr("data-id"));
});
Any best practices?
you don’t need to use attr()
jQuery.data() reads html5
data-attributes using data() method which is also a method for storing data objects in an elementhttp://api.jquery.com/data/
As far as only being html 5, lots of bogus attributes have been used for years, browsers typically just ignore them