[Solved] Detect attribute(type) change of input element [closed]


This is an interesting problem, In javascript we dont have any straight approach with which we can detect the type or attribute change in javascript. I had same kind of problem and then after some studies, I found that this could be done with Mutation observer.
In this code I have created an extension method for HTMLElement and all we have to do is get the reference of that HTMLElement and call this extension function and pass the callback, which we want to be run on attribute change.

HTMLElement.prototype.onAttributeChange = function (c) {
    let observer = new MutationObserver(c);
    observer.observe(this,{attributes:true});
};
var elem=document.getElementById("txtpassword");
elem.onAttributeChange(function(){
        alert("attribute changed");
});
<html>
    <title> 
    </title>
    <head>
    </head>
    <body>
        <input type="password" name="password" id="txtpassword" >
        
    </body>
</html>

solved Detect attribute(type) change of input element [closed]