user-defined element properties: cross-browser?

Discussion in 'Javascript' started by Timo, Feb 3, 2005.

  1. Timo

    Timo Guest

    I've noticed that this is possible in IE:

    <span class='sweetfeature' myproperty='Napoleon Dynamite'
    onclick="ShowProperty(this);" >
    Click here for the name of a hilarious movie.
    </span>

    and then in a script:

    function ShowProperty(e) {
    alert(e.myproperty);
    // or
    // alert(e['myproperty']);
    }

    Is there a counterpart functionality in Firefox, NS, and Opera, or is this a
    proprietary MSFT feature that the other browser vendors do not support?
    Thanks
    TR
    Timo, Feb 3, 2005
    #1
    1. Advertising

  2. Timo wrote:

    > Is there a counterpart functionality in Firefox, NS, and Opera


    Depends on the doctype you use. What you showed is not valid HTML.

    ciao, dhgm
    Dietmar Meier, Feb 3, 2005
    #2
    1. Advertising

  3. Timo wrote:

    > I've noticed that this is possible in IE:
    >
    > <span class='sweetfeature' myproperty='Napoleon Dynamite'
    > onclick="ShowProperty(this);" >
    > Click here for the name of a hilarious movie.
    > </span>
    >
    > and then in a script:
    >
    > function ShowProperty(e) {
    > alert(e.myproperty);
    > // or
    > // alert(e['myproperty']);
    > }
    >
    > Is there a counterpart functionality in Firefox, NS, and Opera, or is this a
    > proprietary MSFT feature that the other browser vendors do not support?


    The core DOM offers the getAttribute method for element objects so
    if (e.getAttribute) {
    alert(e.getAttribute('myproperty'));
    }
    is probably what you are looking for.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 3, 2005
    #3
  4. Timo

    Timo Guest

    Thanks for the reply, Dietmar. Do I understand you correctly, that it would
    be possible to achieve this user-defined property functionality
    cross-browser, simply by declaring the appropriate doctype?
    TR

    "Dietmar Meier" <> wrote in
    message news:...
    > Timo wrote:
    >
    > > Is there a counterpart functionality in Firefox, NS, and Opera

    >
    > Depends on the doctype you use. What you showed is not valid HTML.
    >
    > ciao, dhgm
    Timo, Feb 3, 2005
    #4
  5. Timo

    Timo Guest

    Thank you, Martin.

    "Martin Honnen" <> wrote in message
    news:42021fb2$0$820$-online.net...
    >
    > that the other browser vendors do not support?
    >
    > The core DOM offers the getAttribute method for element objects so
    > if (e.getAttribute) {
    > alert(e.getAttribute('myproperty'));
    > }
    > is probably what you are looking for.
    >
    > > Martin Honnen

    > http://JavaScript.FAQTs.com/
    Timo, Feb 3, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oodini
    Replies:
    1
    Views:
    1,762
    Keith Thompson
    Sep 27, 2005
  2. Replies:
    1
    Views:
    495
    Sion Arrowsmith
    Jul 10, 2008
  3. AAaron123
    Replies:
    2
    Views:
    422
    AAaron123
    Oct 7, 2009
  4. Csaba  Gabor

    cross browser FF style SELECT element

    Csaba Gabor, Mar 25, 2006, in forum: Javascript
    Replies:
    0
    Views:
    477
    Csaba Gabor
    Mar 25, 2006
  5. Replies:
    5
    Views:
    191
Loading...

Share This Page