Reputation: 2647
Hello I am new with jQuery and learning so I need your help to fix my issue.
I am using jQuery ajax and I want to remove id attribute from anchor link after ajax success.
For example I have this link:
<a id="like_14" href="javascript:void(0);">Link</a>
And want this
<a href="javascript:void(0);">Link</a>
Note: I don't want to use id="like_14"
after ajax success. completely removed from anchor link.
My Ajax Code Is:
$(function () {
$('.load_more_ctnt .ovrly a').live("click", function () {
var getImageID = $(this).attr("id");
if (getImageID) {
$.ajax({
type: "POST",
url: "<?php echo URL; ?>home/passImageID",
data: "getImageID=" + getImageID,
success: function (html) {
alert(getImageID);
}
});
} else {
//$(".more_tab").html('The End');
}
return false;
});
});
I am getting ID from this variable: var getImageID = $(this).attr("id");
Any Idea?
Thanks.
Upvotes: 3
Views: 1829
Reputation: 4519
success: function (html) {
//alert(getImageID);
$('#'+getImageID).removeAttr('id');
}
Upvotes: 0
Reputation: 23816
replace id with blank:
$("#like_14").attr("id","");
or remove
$("#like_14").removeAttr("id");
Upvotes: 0
Reputation: 25527
You can use .removeAttr()
$("#like_14").removeAttr("id");
Then your code will look like
$(function () {
$('.load_more_ctnt .ovrly a').live("click", function () {
var getImageID = $(this).attr("id");
if (getImageID) {
$.ajax({
type: "POST",
url: "<?php echo URL; ?>home/passImageID",
data: "getImageID=" + getImageID,
success: function (html) {
alert(getImageID);
$("#" + getImageID).removeAttr("id");
}
});
} else {
//$(".more_tab").html('The End');
}
return false;
});
});
Upvotes: 10