Home > DeveloperSection > Beginner > jQuery removeAttr () method

jQuery removeAttr () method


JQuery JQuery 
Ratings:
0 Comment(s)
 6257  View(s)
Rate this:

JQuery removeAttr () method

In JQuery removeAtrr () method is used to remove attributes from each matched elements. By using this method  we can create some custom attribute and remove  attributes in element .In this article I am trying to show you, how we can use removeAttr () method to remove attributes of element on page as shown below:

Syntax :$( “element”).removeAttr (“name”);

Code:

<title>JQuery removeAtrr method</title>

 

    <script type="text/javascript" src="jquery.min.js">//add jquery library in script tag

    </script>

 

    <script type="text/javascript">

        $(document).ready(function() //ready function contain all jquery function

        {

            $("#rcolor").click(function()            {

                $("input").removeAttr("style");//removeAttr method will remove style attribute from all input tags

            });

        });

    </script>

</head>

<body>

    <table width="275" border="2" >         <tr>

            <td align="center">

               <label>Name</label>

            </td>

            <td align="center">

                <input type="text" style="color: Red">

            </td>

          </tr>

           <tr>

            <td align="center">

                <label>Age</label>

            </td>

            <td align="center">

                <input type="text" style="color: Red">

            </td>

          </tr>

           <tr>

            <td align="center">

               <label>City</label>

            </td>

            <td align="center">

                <input type="text" style="color: Red">

            </td>

          </tr>

           <tr>

            <td align="center">

                <label>College</label>

            </td>

            <td align="center">

                <input type="text" style="color: Red">

            </td>

          </tr>

    </table>

    <button>

        Submit</button>

    &nbsp;&nbsp; <button id="rcolor">

        Remove Color</button><!—button element with id-->

</body>

Screenshot

jQuery removeAttr method

If we want to remove font color from textboxes click on remove color button and red color will remove from font as shown below:

jQuery removeAttr method

 


Don't want to miss updates? Please click the below button!

Follow MindStick