2

Background info: I’m studying JavaScript, currently trying to understand DOM interactions, specifically direct selection (dot notation). It is worth noting that i’m a very theoretical learner and need to understand the principles in order to remember how things work and be able to use them properly.

The 3 classic examples given to clarify how direct selection (dot notation) works are:

  • document.documentElement
  • document.head
  • document.body

W3C says that these are the SOME of the most popular ways to select elements directly. So what are the rest? How do i find a full list of all possibilities to select elements via dot notation, and the principles behind how this works?

For example, i tried document.head.title, but that seems to be wrong… And some places suggest it is document.title, while other sources suggest it is limited to only those 3 options in the classical examples.

How does this whole DOM direct selection (dot notation) work? Can’t i navigate fully like this? Do i need to include the whole path or not? Does it work only on unique HTML tag elements? Or any HTML tag elements?

What are the principles behind this? I can’t find any information that actually explains this, except maybe MDN, but i find the language there is very unclear, so any clarification is very welcome.

Thanks in advance.

4get
  • 21
  • 1
  • 1
    _"Can’t i navigate fully like this?"_ - no, you can't, because this is only available for a couple of "special" elements, that people very frequently need access to. – CBroe Jun 24 '22 at 11:57
  • Those are starting points for navigation. Use `document.head.querySelectorAll()` or `document.body.querySelector` to "navigate". – Ruan Mendes Jun 24 '22 at 12:01
  • *"It is worth noting that i’m a very theoretical learner and need to understand the principles in order to remember how things work and be able to use them properly."* Lucky you, the only way I learn is by doing. Do you have any broken code we can fix for you? – zer00ne Jun 24 '22 at 12:50
  • @zer00ne this is actually very difficult to learn to code this way, because people hardly ever explained the principles, and even when they do, it is often very limited and not complete - so i end up second guessing everything about what don't i know that i don't know yet? At least if i knew that i don't know something, i could look it up... but blind-spots... How do you deal with that? To answer your question. No. I don't have any broken code. I am just trying to understand it. – 4get Jun 24 '22 at 14:42
  • This is a site to post a question concerning broken code, please read [ask]. – zer00ne Jun 24 '22 at 16:41
  • 1
    @zer00ne, nowhere in your link does it say that questions must be about broken code. It even says "Not all questions benefit from including code..." And examples of good questions: Good: Why does using float instead of int give me different results when all of my inputs are integers? Good: How can I redirect users to different pages based on session data in PHP? Good: Why does str == "value" evaluate to false when str is set to "value"? none of these are examples of broken code. – 4get Jun 25 '22 at 09:42
  • What are those questions about then? Each of those questions clearly implies that some result was expected yet they have unexpected results and want to know why. Code that returns unexpected, and unwanted results is broken code. When you actually start to write code you'll understand eventually. – zer00ne Jun 25 '22 at 09:53
  • 1
    @zer00ne, they are questions about how the code works (in principle). No code is provided. Same here. It is a question about how dot notation works. What are all the possible objects for dot notation? Where can i find the list? How does it work behind the scenes? When i understand the principles, then i won't have to ask 50 times about every possible permutation of broken code. I will understand how to use it in all cases. And that is what i am trying to understand. – 4get Jun 25 '22 at 11:05
  • *"Why does str == "value" evaluate to false when str is set to "value"? "* That is a question you get from someone who needs help making their code work: `str == "value"` but it returns `false`. Why would the help section need to show contrived examples that serve no purpose. If you were actually serious about learning you'd start coding something instead of beating a dead horse. *"What are all the possible objects for dot notation? "* is just like asking *"what are all of the conjunctions of the English language, how do they all work?"* That can be researched. – zer00ne Jun 25 '22 at 12:36

0 Answers0