Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery how to remove id tag from anchor

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.

like image 798
Mr.Happy Avatar asked Nov 28 '25 16:11

Mr.Happy


2 Answers

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;
    });
});
like image 168
Anoop Joshi P Avatar answered Dec 01 '25 05:12

Anoop Joshi P


Use .removeAttr() in jquery.

$(this).removeAttr("id");
like image 37
Sudharsan S Avatar answered Dec 01 '25 05:12

Sudharsan S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!