Object Doesnt Support this Property or Method (IE)

I recently encountered this problem using Javascript and Internet Explorer. It worked perfectly fine in other browsers although (for a change) I think MSHTML has got this right enforcing good practice.

Object Doesnt Support this Property or Method can occur in Internet Explorer when you declare a variable that has the same name as a document object. For example the snippet below will produce an error/warning in Internet Explorer:

1
2
3
<script type="text/javascript">
MyTest = document.getElementById('MyTest');
</script>

The document object “MyTest” was already declared inside a HTML div block and Internet Explorer doesn’t allow you to reference an element with the same name.

To avoid this simply provide a unique name (different to that of the element) like shown in the snippet below:

1
2
3
<script type="text/javascript">
UniqueName = document.getElementById('MyTest');
</script>

Leave a Reply


Website Designed and maintained by Daniel Gibbs - Powered by WordPress - Copyright 2009