Forum Moderators: open
I've defined some functions for HTML elements in my script using:
Element.prototype.somefunction= function(){function_body}
etc.
It works brilliant in firefox but of course internet explorer has issues with it. I get the error: 'Element is not defined'.
I read on some blog that this can be fixed with adding a 'HTC file' but I didn't really understand the explanation of how to do it.
Is there someone who can explain this to me or, better, who has an easier solution for this problem?
tnx
<script type="text/javascript">
window.onload = function () {stinky.weirdnoise(); stinky.strangenoise();};
function Element(){
this.betterGetThatChecked = "prhraaappp bbloooop splaupp";
var badsound = "phhoooootttt";
this.weirdnoise = function () {
alert(badsound);
};
}
Element.prototype.strangenoise = function () {
alert(this.betterGetThatChecked);
};
stinky = new Element();
</script>
Element.prototype.getParentBy=function(prop, val){
a=this.parentNode
while(a.tagName!="BODY"){
if(a[prop]==val){ return a;}
a=a.parentNode;
}
return false;
}
it searches for the first parent of an element with the specified property and value, i.e.
someHTMLelement.getParentBy("className", "container")
I really don't want to define this function for every specific element I might want to use it on so that's no solution.
I hope this is enough information. It works fine in firefox and I'd really like to get it to work in IE also, so any solution, even one with a 'HTC' file (allthough I have no idea whatthose are) would be greatly appreciated.
function getParent( Element, prop, val){ ... }
Not great but better than this ? [msdn.microsoft.com...]