Allowed Element property value's?

46 views
Skip to first unread message

Ed

unread,
Jul 4, 2013, 11:01:56 AM7/4/13
to google-we...@googlegroups.com
While debugging, I have a dom Element that looks like (Element.toString()):
<span id="_TxMrk_19" key="amt"></span>

When reading the property value I get the following:
element.getPropertyString("id")  ->  "_TxMrk_19"
element.getPropertyString("key")  -> null

Why does reading the "key" property value returns in null? (I would expect "amt")...
(using gwt. 2.5.1 in dev mode against FF, with plugin).
- Ed

Jens

unread,
Jul 4, 2013, 11:11:09 AM7/4/13
to google-we...@googlegroups.com
Maybe 'key' is some sort of reserved attribute. Try rename it to data-key. As of HTML5 the "data-" prefix should be used for custom attributes.

-- J.

Ed

unread,
Jul 4, 2013, 2:19:46 PM7/4/13
to google-we...@googlegroups.com
> Try rename it to data-key. As of HTML5 the "data-" prefix should be used for custom attributes.
Hmmm.. I was sure this would work, but doesn't :(

I see this: 
<span id="_TxMrk_19" data-key="amt"></span>
But get this:
 element.getPropertyString("data-key")  -> null

Can somebody try this?

Note: It concerns a HTMLPanel that is created with a html string containing this span element. I then browse the elements to retrieve the key. I tried it both when the element is attached and not attached.
- Ed 

Jens

unread,
Jul 4, 2013, 2:43:50 PM7/4/13
to google-we...@googlegroups.com
Oh, just realized that you have used getPropertyString(). You better use getAttribute().

-- J.

Jens

unread,
Jul 4, 2013, 2:48:38 PM7/4/13
to google-we...@googlegroups.com
To be more precise:

You can use getProperty() for actual properties like id. A list of all properties of a DOM element: https://developer.mozilla.org/en-US/docs/Web/API/element

For everything else you have to use getAttribute().

-- J.

Ed Bras

unread,
Jul 4, 2013, 3:18:48 PM7/4/13
to google-we...@googlegroups.com
That did the trick ;).. Thanks, it works when using getAttribute().
I tried that before, but got an exception because I was doing a getAttribute() on a text Note (using instanceof Element instead of Element.is(..) ;).

And from this stackoverflow post, I thought that I should use getProperty() after reading Daniel his explanation:

A bit confusing this Property/attribute thing...
- Ed




-- J.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/_W_6ZLRHhm0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jens

unread,
Jul 4, 2013, 4:19:13 PM7/4/13
to google-we...@googlegroups.com

A bit confusing this Property/attribute thing...

Yeah. Nice link. 

I think I haven't got it right either but at least getAttribute works. Also if you name the attribute 'data-key' I think you have to use getPropertyString('dataKey').

-- J.

David

unread,
Jul 4, 2013, 4:52:19 PM7/4/13
to google-we...@googlegroups.com
Hi,

Attributes are part of the html markup (tag attributes). Parameters are object parameters of the DOM JavaScript object.

David


-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.

Ed Bras

unread,
Jul 4, 2013, 5:28:21 PM7/4/13
to google-we...@googlegroups.com
@David: thanks for the short and clear explanation.
I googled a bit more, and did find this also useful:

Reply all
Reply to author
Forward
0 new messages