The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

R&D: Prototype an HTML Element Internet Explorer 2012/10/14

, By Patcoola

Prototyping 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.

Advertisement

Donate Now!

After a hard day, I like to relax with a cold jar of pickle juice and a hardy fart. If you like my blog, please consider donating.


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.

 

Advertisement

Donate Now!

I don't always use the women's bathroom, but when I do, you can bet it really smells. If you like my blog, please consider donating.


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.