Saying that document.getElementById returns HTML - you are mistaken. This method returns an instance of the Element class.
Seeing this is quite simple. Here is the code:
var el = document.getElementById('text'); console.log(el instanceof Element);
will print true ( proof ) to the console.
As for the NodeList , document.getElementById in no case return an instance of this class, since, according to the standard, the id attribute must be unique within the document.
The behavior of jQuery here can be explained by considerations of uniformity: by wrapping an element ( Element ) you get a collection of nodes containing exactly one element.
If you still need a NodeList instance and you don’t want to use jQuery, you can use the document.querySelectorAll method:
var el = document.querySelectorAll('#text'); console.log(el instanceof NodeList);
JSFiddle working example .
Element. developer.mozilla.org/ru/docs/Web/API/Document/getElementById - Sublihimconsole.log(el instanceof jQuery, el instanceof NodeList); //true, falseconsole.log(el instanceof jQuery, el instanceof NodeList); //true, false- Alex Krass