[jQuery] Getting "this" to work with my function and jquery
I might be getting confused about the proper use of "this". I thought
I understood how this worked, and that since I am triggering the
onclick even on an anchor, that the "this" would be in the context of
that anchor tag, so that I could grab its href.
Here is what I have done, but it is returning undefined for asseturl.
function deleteAjaxAsset(message, assetid) {
var asseturl = $(this).attr("href");
alert(asseturl);
var confirmDelete = confirm(message);
if (confirmDelete == true) {
if(action == "delete") {
$.ajax( {
type : "POST", url : asseturl + "?action=delete" }
);
}
}
}
<a href="http://www.testpage.com" onclick="deleteAjaxAsset('Are you
sure you want to delete?','testid'); return false;">Delete</a>
Thanks guys!