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.
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;
});
});
在jquery中使用.removeAttr()
。
$(this).removeAttr("id");
replace id with blank:
$("#like_14").attr("id","");
or remove
$("#like_14").removeAttr("id");
success: function (html) {
//alert(getImageID);
$('#'+getImageID).removeAttr('id');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.