You can have multiple elements with the same class name as narrowing your search to start with a specific node meaning.
This does not make sense with id, because it must be unique.
There can only be one id
in document
, so getElementById
is the document
method.
Example:
<body> <div id="start"> <span class="a"> </div> <div class="a"> </div> </body>
Starting a class search from node <div id="start">
will give you one element,
Although, if you started with the top node document, it would end with two elements.
Regarding typeof
comparison:
typeof 1 == typeof 2 == "Number" // true 1 !== 2 // true.
typeof
only checks the type, not the value, document
and document.body
are both objects, but different objects.
typeof document === typeof document.body === typeof null === "object" // true document === document.body // false!!!
As you can see, null
and document
use the same type, but do they have the same methods ...? NOT
source share