Accessing properties of HTML Elements

18 views
Skip to first unread message

Greg

unread,
Apr 17, 2012, 6:10:24 AM4/17/12
to domass...@googlegroups.com
I love DOMAssistant's simplicity. I'm planning on bundling it with my currently in development open source project, but I need to figure out what I'm doing wrong in this simple use case.

Accessing the "special" properties or methods of the DOMAssistant object, like $( ... ).addEvent( ... ) or $( ... ).load( ... ) works as I would expect, but to access the standard properties and methods of the returned HTML Elements, I seem to have to specify the key on which to manipulate.

For example:

$("p").innerText = "Test"; // Does not work.

I would expect that to change all paragraphs' innerText property to "Test", but instead, I get the error that the object does not have the property "innerText", and to fix this I have to specify what index of the returned array to access..
.. like this:

$("p")[0].innerText = "Test"; // Works.

Can anyone give me any advice on where I'm going wrong?

Cheers.

Robert Nyman

unread,
Apr 17, 2012, 7:27:58 AM4/17/12
to domass...@googlegroups.com
Haven't been dabbling with DOMAssistant in years, but I'd say that is in line with how jQuery and other JavaScript libraries do it as well.
For a direct element reference for one element and to access properties, you can use the $$ method. E.g:

$$("container");

However, if you want more than one, you need to either access it by array index or iterate over all returned matches with a loop.


Best regards,
Robert


--
You received this message because you are subscribed to the Google Groups "DOMAssistant" group.
To view this discussion on the web visit https://groups.google.com/d/msg/domassistant/-/vKB3UyhjKsgJ.
To post to this group, send email to domass...@googlegroups.com.
To unsubscribe from this group, send email to domassistant...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/domassistant?hl=en.

Reply all
Reply to author
Forward
0 new messages