Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does getting the documentElement of 0 return

Tags:

javascript

dom

most javascript libraries contain lines similar to:

    var b = (a ? a.ownerDocument || a: 0).documentElement;

if a is null, what is (0).documentElement supposed to return?

like image 627
eych Avatar asked Sep 11 '13 13:09

eych


People also ask

What is documentElement return?

documentElement returns the Element that is the root element of the document (for example, the <html> element for HTML documents).

What is document getElementById () value?

The getElementById() method returns an element with a specified value. The getElementById() method returns null if the element does not exist. The getElementById() method is one of the most common methods in the HTML DOM. It is used almost every time you want to read or edit an HTML element.

What does getElementById return?

Document.getElementById() The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.

Can we use document getElementById in node JS?

var element = document. getElementById("YourElementId"); Using a different strategy, which is described below with code samples, the identical issue How To Get Element By Id In Node Js can be resolved. var myElement=document.


2 Answers

From jQuery / Sizzle comments:

http://jsapi.info/jquery/1.7.2/jQuery.isXMLDoc

documentElement is verified for cases where it doesn't yet exist (such as loading iframes in IE - #4833)

So it's just cute syntax for returning undefined - this is a result of calling documentElement on 0.

In next line there is check:

return documentElement ? documentElement.nodeName !== "HTML" : false;

So it returns false anyway.

like image 170
hsz Avatar answered Sep 28 '22 01:09

hsz


most probably: undefined what else?

like image 23
justaprogrammer Avatar answered Sep 28 '22 00:09

justaprogrammer