Mr.Happy
Mr.Happy

Reputation: 2647

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.

Upvotes: 3

Views: 1829

Answers (4)

Dimag Kharab
Dimag Kharab

Reputation: 4519

success: function (html) {
                        //alert(getImageID);

                       $('#'+getImageID).removeAttr('id');
                    }

Rerence

Upvotes: 0

Manwal
Manwal

Reputation: 23816

replace id with blank:

$("#like_14").attr("id","");

or remove

$("#like_14").removeAttr("id");

Upvotes: 0

Sudharsan S
Sudharsan S

Reputation: 15393

Use .removeAttr() in jquery.

$(this).removeAttr("id");

Upvotes: 2

Anoop Joshi P
Anoop Joshi P

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

Related Questions