Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Object.prototype help

    Hey everyone

    I'm scrambling to become more familiar with OO concepts, and specifically applying them to my javascript. So, as part of my self-education, I'm messing with prototype. I've done, this, but get a "not supported method" error.
    Code:
    <html>
    <title>Prototype testing</title>
    <head>
    <script type="text/javascript">
    TR.prototype.toggle = function() {
    	this.style.backgroundColor = 'red';
    	}
    </script>
    
    </head>
    
    <body>
    <table cellspacing="1">
    <tr onMouseOver="this.toggle()"><td>1</td><td>2</td><td>3</td></tr>
    <tr onMouseOver="this.toggle()"><td>1</td><td>2</td><td>3</td></tr>
    <tr onMouseOver="this.toggle()"><td>1</td><td>2</td><td>3</td></tr>
    </table>
    </body>
    </html>

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    IE's HTMLElement's are all screwed up - you'll find they don't even inherit from Object!

    So far, only Mozilla exposes prototypes of HTMLElement's:

    HTMLTableRowElement.prototype.toggle = function() {
    this.style.backgroundColor = 'red';
    }

    See http://www.w3.org/TR/2002/CR-DOM-Lev...0605/html.html for a list of interfaces you can use.

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I see, so can I not do this in IE period?


  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Not in this fashion. You could resort to a behavior (just like you could resort to Moz's XBL):

    tr {
    behavior: url(bla.htc);
    }

    and inside bla.htc have:

    <script type="text/javascript">
    element.toggle = function() {
    element.style.backgroundColor = 'red';
    }
    </script>


    But that's not really extending your OO knowledge, now is it?

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, it's not

    Thanks, I know behaviors and XBL (a little)

    Got a good reference link for XBL?

    NS6 sees -moz-binding :url(blah); right?

  • #6
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by beetle
    NS6 sees -moz-binding :url(blah); right?
    Yes. See XBL 1.0 specification, but beware, the current XBL implementation in Mozilla is not yet the 1.0 phase, which means a lot of the features in that document currently don't exist, or been disabled to stability, etc.
    This is documentation of the current implementation. But it is on a webbased CVS interface, which means non-CVS people might get slightly confused, but you can always start here and follow links without worrying about CVS extras.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •