Drahcir Drahcir - 9 months ago 48
Javascript Question

What JSDoc type is document.getElementById('myID')?

I'm trying to document my functions with JSDoc syntax.

* My Description
* @param {JQuery|???} input
* @returns {JQuery}
function foo(input){
return $('selector');

The above function accepts a single argument which can be either a JQuery object, or an element returned by

What is the valid JSDoc type for the return value of

For example, the following are both valid:


Also, where can I find this out in future?


getElementById will always return a subtype of Element. In the case of an HTML document, HTMLElement will be more appropriate

document.getElementById('some-anchor').constructor //HTMLAnchorElement
document.getElementById('some-div').constructor //HTMLDivElement

In all cases, document.getElementById('some-element') instanceof HTMLElement will, IMHO, return true