parsing DOM with Javascript, to read HTML tag info

D

devvan

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.
 
M

Martin Honnen

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');
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top