How to use DOM Element HasAttribute in JavaScript

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

JavaScript DOM Element hasAttribute() Method

JavaScript hasAttribute() method use for check specified attribute exists or not exists. If attribute exists then it will return true other wise false.


element.hasAttribute(attribute name)




    <script type="text/javascript">


        function myfun() {

            var mm = document.getElementsByTagName("BUTTON")[0];

            var pp = document.getElementById("tst");

            pp.innerHTML = mm.hasAttribute("onclick");






    <p id="tst">

        click button for check element exists or not exists</p>

    <button onclick="myfun()">

        click me</button>








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.