All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Remove Readonly Attribute jQuery

Last Updated : Mar 11, 2024

Remove Readonly Attribute jQuery

In this article we will show you the solution of remove readonly attribute jQuery and we will learn about how to remove readonly attribute from a form html element using jquery. Here we needs to use removeAttr(), text() and click() methods.

The text() method used for append some text on html element in webpage and removeAttr() method used for removes one or more attributes from the selected elements.

So here we can remove readonly attribute from input element.

Step By Step Guide On Remove Readonly Attribute jQuery :-

Here we defined html block with h1 tag for displays heading, input element defined with id ,value ,name and readonly attributes, para element for display result and button ‘Remove Readonly’ defined with id attribute.

In script block we defined ready() method which is automatically starts loading code of within this function when this program opened on browser and within that we waiting for click event occurrence which is appended with button.

There we specified readonly attribute on removeAttr() method for removing purpose and it is appends with input element ‘inp’.

<!DOCTYPE html>
<html>
    <head>
        <title>Remove Readonly</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $("#rr").click(function(){
                    $("#inp").removeAttr('readonly');
                    $("p").text("Now You Can Edit Textbox Input...")
                })
            });
        </script>
    <body>
        <h1>Readonly Enabled On Textbox</h1>
        <input type="text" name="nm" id="inp" value="Hi am Keth" readonly>
        <p></p>
        <button id="rr">Remove Readonly</button>
    </body>
    </head>
</html>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contain information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Here we imported open source jquery library support file which is needed for coding using jquery in program.
  5. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  6. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  7. In script we defined ready() method within that we defined click() method which is appends with button by using id attribute ‘rr’ for generates click event when user clicks on ‘Remove Readonly’ button.
  8. Within function we needs to specify which elements readonly attribute to be remove so we specified input element by id ‘inp’. Then removeAttr() method contain readonly attribute and it is appended with input element ‘inp’ which is finally removed from input tag.
  9. For users verification purpose we appended text ‘Now You Can Edit Textbox Input...’ on p tag by using text() method.
  10. In html block we defined h1 element with heading ‘Readonly Enabled On Textbox’, input element defined with name, id, value and readonly attributes with respected values ‘nm, inp, Hi am Keth’, p element defined for display result and button ‘Remove Readonly’ defined with id ‘rr’.
  11. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to remove readonly attribute from specific html form element using jquery.

Before execution of program we needs to confirm internet connection because then only that jquery file will supports defined jquery codes without error.

When we executes program on browser we can see ‘Readonly Enabled On Textbox’, input box with value ‘Hi am Keth’ which is initially not editable because of enabled readonly attribute now user needs to click on button ‘Remove Readonly’ then we can see notification of ‘Now You Can Edit Textbox Input...’ message so now you can edit input box value because we successfully removed readonly attribute.

I hope this article on remove readonly attribute jQuery helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪