Skip to content
Related Articles

Related Articles

Improve Article

How to remove clickable behavior from a disabled link using jQuery ?

  • Last Updated : 24 Mar, 2021

In this article, we will see how to remove the clickable behavior from a disabled link using jQuery. To remove the clickable behavior, we will use removeAttr() method. The removeAttr() method is used to remove one or more attributes from the selected elements.

Syntax:

$(selector).removeAttr(attribute)

Parameters: This method accepts single parameter attribute that is mandatory. It is used to specify one or more attributes to remove. Several attributes can be separated using space operator.

In this article, we will remove the href attribute using removeAttr() method.

Example:

HTML




<!DOCTYpe html>
<html>
  
<head>
    <title>
        How to remove clickable behavior from
        a disabled link using jQuery?
    </title>
  
    <script src=
    </script>
  
    <script>
        $(document).ready(function () {
            $("body").css("text-align", "center");
            $("h1").css("color", "green");
            $("a").css({
                fontSize: "34px",
                fontWeight: "bold",
                color: "green",
                textDecoration: "none"
            })
            $("a").each(function () {
                if ($(this).hasClass("disabled")) {
                    $(this).removeAttr("href");
                }
            });
        });
    </script>
</head>
  
<body>
    <a href="https://www.geeksforgeeks.org/" 
        class="disabled">
        GeeksforGeeks
    </a>
  
    <h3>
        How to remove the clickable behavior from
        <br>a disabled link using jQuery?
    </h3>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :