nikoloz
nikoloz

Reputation: 67

html element - property of document object ? or an object?

so, html elements such as <title>are sometimes referred as property, but sometimes they are referred as objects. i am kinda confused. are html elements properties of document object? or are they objects? or are they both at the same time? thanks. to make question meet quality standards i will add some random codes.

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

</body>
</html>

Upvotes: 0

Views: 316

Answers (4)

Michael B.
Michael B.

Reputation: 351

The document object has a title property, which is a string, which is an object. But the document object does not have direct properties for the html elements in the page, that's why you have accessor functions like document.getElementById('id'), which return objects representing html elements. Open up a console in chrome and type document. to see all the properties the document object has. Also see that document.title and document.getElementByTagName('title')[0] do not return the same thing.

Upvotes: 0

Breno Inojosa
Breno Inojosa

Reputation: 602

They are two separate things. Element is the HTML element or tag. Javascript and jQuery (which is also Javascript), for example, modify and control the HTML elements by using the HTML DOM (HTML Document Object Model). The DOM contains the Objects you're referring to. Each DOM object refers to an element and when the Javascript modifies your HTML page, it's actually accessing the DOM, not the HTML elements.

Take a look at: http://www.w3.org/TR/DOM-Level-2-Core/introduction.html.

Upvotes: 0

Andrew
Andrew

Reputation: 43103

The DOM, or Document Object Model is a tree. The HTML document available at window.document is the root node of this tree.

Essentially everything else in the document is a node somewhere in this tree, whether it is an element like <p> or an attribute node like class="foo" or a text node. Each of these nodes are objects that you can interact with via Javascript.

Upvotes: 0

magic-sudo
magic-sudo

Reputation: 1236

The document itself is a document node. All HTML elements are element nodes. All HTML attributes are attribute nodes. Text inside HTML elements are text nodes. Comments are comment nodes. In the HTML DOM, the Element object represents an HTML element.

DOM w3schools

Upvotes: 1

Related Questions