Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prototyping HTMLElement in NS6 1

Status
Not open for further replies.

jaredn

Programmer
Sep 1, 1999
1,506
US
This discovery amazed me. Apparently, in Netscape 6, all HTML elements inherit from a base object called HTMLElement. Because of this, we can add methods to this base object using prototype, and all of our elements will have these methods(/properties?) available to them. For a simple example:

<body onLoad=&quot;document.getElementById('ben').move(170,300)&quot;>

<div id=&quot;ben&quot; style=&quot;position:absolute;&quot;>
dsfsdgsfgfs
</div>

<script>

HTMLElement.prototype.move = function(x,y)
{
this.style.left = x+&quot;px&quot;;
this.style.top = y+&quot;px&quot;;
}

</script>

Test this in NS6. If anyone knows of a similar object like HTMLElement in IE, please tell me!

Thanks to Erik from for helping me realize this by mistake :) jared@aauser.com
 
wow, jaredn, that's really neat. adam@aauser.com
 
ok here's something that erik helped me with, for adding a hide method to all elements in IE5.5+ only:

oStyleSheet.addRule(&quot;*&quot;, &quot;behavior: url('javascript:generateCode()')&quot;);

function generateCode() {
return &quot;<public:component>&quot; +
&quot;<public:method name='hide'/>&quot; +
&quot;<script>&quot; +
&quot;function hide() {&quot; +
&quot; element.style.visibility = \&quot;hidden\&quot;;&quot; +
&quot;}&quot; +
&quot;</script>&quot; +
&quot;</public:component>&quot;
} jared@aauser.com
 
(Note: haven't been able to get above code to work yet, when I do, I'll repost) jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top