Understanding The Relationship Between HTML DOM Element Properties [projs3e]

Skip to first unread message

Andy Michalski

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"


Nicholas Zakas

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

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

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