0

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>
5
  • Why do you need this information ? Do you want to use it in Jquery? Commented Jan 14, 2015 at 19:10
  • 1
    just starting to learn DOM, and javascript, it kinda bothers me when i dont get something :D Commented Jan 14, 2015 at 19:13
  • sometimes properties are objects: {a:{b:1}}... did i blow your mind? Commented Jan 14, 2015 at 19:15
  • It depends on what exactly you are referring to. Look at it this way. Before teh dom is parsed, <tite>Hello!</title> is a tag. After the DOM is parsed, it will be an element that is a childNode of the <html> node, which is part of document. The text content of the title element will also be set as the value of document.title (title being a property of document.) So, to answer your question.... Yes, Yes, and Yes Commented Jan 14, 2015 at 19:15
  • document.title is basically an internal shortcut to document.getElementsByTagName("title")[0].textContent Commented Jan 14, 2015 at 19:17

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.