Understanding The Relationship Between HTML DOM Element Properties [projs3e]

23 views
Skip to first unread message

Andy Michalski

unread,
Mar 20, 2019, 5:08:09 PM3/20/19
to Zakas Books
Hello Nicholas,

Hope all is well with you. I have a question about the example on page 328 from Chapter 10 of Professional JavaScript for Web Developers (Third Edition).

In your example you select an element from the DOM:

var div = document.getElementById("myDiv");
And access its properties like this:

div.id;            //"myDiv"
div.className;     //"bd"
div.title;         //"Body text"
My question is what happens behind the scenes. Are you basically creating a new object like this?

var div = {
    id: "myDiv",
    className: "bd",
    title: "Body text"
};
Best,

-Andy

Nicholas Zakas

unread,
Mar 21, 2019, 2:57:52 PM3/21/19
to zakas...@googlegroups.com
Hi Andy,

Each DOM element type has its own constructor; in this case, a new HTMLDivElement instance is created. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLDivElement

Regards.
--
You received this message because you are subscribed to the Google Groups "Zakas Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zakasbooks+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andy Michalski

unread,
Mar 21, 2019, 3:39:34 PM3/21/19
to Zakas Books
I see. Thanks!
Reply all
Reply to author
Forward
0 new messages