Hello I am new with jQuery and learning so I need your help to fix my issue.
您好我是jQuery的新手并且正在学习,所以我需要您的帮助来解决我的问题。
I am using jQuery ajax and I want to remove id attribute from anchor link after ajax success.
我正在使用jQuery ajax,我想在ajax成功后从锚链接中删除id属性。
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.
注意:在ajax成功之后我不想使用id =“like_14”。完全从锚链接中删除。
My Ajax Code Is:
我的Ajax代码是:
$(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");
我从这个变量中获取ID:var getImageID = $(this).attr(“id”);
Any Idea?
Thanks.
4 个解决方案
#1
10
You can use .removeAttr()
你可以使用.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;
});
});
#2
2
Use .removeAttr()
in jquery.
在jquery中使用.removeAttr()。
$(this).removeAttr("id");
#3
0
replace id with blank:
用空格替换id:
$("#like_14").attr("id","");
or remove
$("#like_14").removeAttr("id");
#1
10
You can use .removeAttr()
你可以使用.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;
});
});
#2
2
Use .removeAttr()
in jquery.
在jquery中使用.removeAttr()。
$(this).removeAttr("id");
#3
0
replace id with blank:
用空格替换id:
$("#like_14").attr("id","");
or remove
$("#like_14").removeAttr("id");