Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > parsing DOM with Javascript, to read HTML tag info

Reply
Thread Tools

parsing DOM with Javascript, to read HTML tag info

 
 
devvan@gmail.com
Guest
Posts: n/a
 
      11-08-2006
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.

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-09-2006
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
read html file into org.w3c.dom.html.htmldocument Jozza Java 1 03-04-2010 11:22 AM
Parsing an XML file and adding another tag, if the tag is not available / the value is null P Perl Misc 7 01-12-2007 03:28 AM
HTML.Tag.BASE same as HTML.Tag.A carlbernardi@gmail.com Java 1 11-29-2006 03:41 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Convert a XML DOM Object to a HTML DOM Object manjunath.d@gmail.com XML 0 09-20-2005 08:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57