This blog uses responsible cookies for functionality and user preferences.
Google Analytics is used for collecting general public information to understand how my blog is used.
Learn morePrototyping an HTML Element in Internet Explorer, is not as perfect as other Web browsers, Internet Explorer has been slow to catch on to newer modern features. These research and development notes focus on two issues related to Internet Explorer earlier than version 9. Issue one, prototyping a HTML element. Issue two, determining if a prototyped property is a string or an element.
Most modern Web browsers allow an HTML Element to be prototyped with Java Script, but with Internet Explorer (IE), we only see this functionality with version 9 and above.
For those who want to see an example of a Java Script prototyped to an HTML Element, the example below illustrates it’s usage.
document.getElementById(“myElement”).myfunction();
In IE 9 and above, this would be acceptable but not in earlier versions of IE.
There is a solution, we need to detect the IE version for IE versions below 9, then we need to create the Element instance, because it does not exist. However, we actually can’t just create it, a workaround found on the Internet says we can create an attribute with the prototype function attached to the element.
Allowing either a string or an element to be prototyped with the same function.
The example below illustrates how the two would look like.
document.getElementById(“myElement”).myfunction();
OR
“myElement”.myfunction();
In this case, we want the string to be the element ID, the function would have to detect whether the property is an Element or a String, if it is a string then the document.getElementById would be defined within the function.
The problem is that IE versions older than 9 do not have the ability to detect the instance of a HTMLElement, however, a HTMLElement is also defined as an object type, this can be confusing because other data types such as an Array is also defined as an object.
The solution, test for the instance of an HTML element, catch the error and then try checking the node type for type one.
Terms of Use, Cookies, Privacy, and more, see Terms and Privacy
Third-party copyrights and trademarks featured on this site are owned by their respected holders.
Website written and designed by Patcoola 2019, some rights reserved.
This blog uses responsible cookies for functionality and user preferences.
Google Analytics is used for collecting general public information to understand how my blog is used.
Learn moreDear EU visitor, I am required to ask you consent for the following.