parsing DOM with Javascript, to read HTML tag info

Discussion in 'Javascript' started by devvan@gmail.com, Nov 8, 2006.

  1. Guest

    I need to get information about certain fields in an HTML tag. "Field"
    may be the incorrect term, but what I mean is the information stored in
    "thing" or "widgetId" in the HTML tag below.

    <div dojoType="Button" thing="foo" id="bar"
    widgetId="theButton2">Grumble, grumble...</div>

    I have Javascript listener in an HTML web page. On an event, a
    function call in invoked, and in this function:
    var curEvent = event || window.event; //either browser
    var sourceEl = curEvent.tft || curEvent.srcElement; //either browser

    I am interested in finding the name (in string format) of the DOM
    element that generated the event. I iterate though the objects in
    "sourceEl" until I find "parentElement". I am satisfied that I have
    found the "parentElement" object that corresponds to the button that
    generated the event, but what I cannot do from here is access the
    fields in this tag. Trying to dereference the fields like
    thing/id/widgetId with a dot operator only yields "undefined".

    Do those those fields even exist at the time that I'm attempting to
    read them?
    Thanks.
    , Nov 8, 2006
    #1
    1. Advertising

  2. wrote:
    > I need to get information about certain fields in an HTML tag. "Field"
    > may be the incorrect term, but what I mean is the information stored in
    > "thing" or "widgetId" in the HTML tag below.
    >
    > <div dojoType="Button" thing="foo" id="bar"
    > widgetId="theButton2">Grumble, grumble...</div>


    These are custom attributes, if the DOM implementation exposes them then
    you can get at them with getAttribute('attributeName') e.g.
    var div = document.getElementById('bar');
    var widgetId = div.getAttribute('widgetId');

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 9, 2006
    #2
    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. shruds
    Replies:
    1
    Views:
    757
    John C. Bollinger
    Jan 27, 2006
  2. Replies:
    0
    Views:
    538
  3. Replies:
    1
    Views:
    364
    Andrew Thompson
    Nov 29, 2006
  4. Jozza
    Replies:
    1
    Views:
    1,832
    Jozza
    Mar 4, 2010
  5. P
    Replies:
    7
    Views:
    131
    Tad McClellan
    Jan 12, 2007
Loading...

Share This Page