Drahcir Drahcir - 1 year ago 79
Javascript Question

What is the JSDoc type for document.getElementById('myID') and a jQuery Element?

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download