How to use DOM Element SetAttribute in JavaScript

In this article I am going to explain about DOM element setAttribute() method in JavaScript.
  • 1837

JavaScript DOM Element setAttribute() Method

JavaScript setAttribute() method use for set specified attribute instead of old attribute and give specified value. If both attribute are same then only value will be change.


element.setAttribute(attribute name, attribute value)




    <script type="text/javascript">


        function myfun() {

            document.getElementsByTagName("INPUT")[0].setAttribute("type", "radio");






    <input value="hello" />

    <p id="demo">

        click button to set attribute</p>

    <button onclick="myfun()">

        click me</button>






Before click




After click




You may also want to read these related articles: here
Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.