Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Is in DOM
Check if given element is in dom
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
isInDOM1
718859.5 Ops/sec
isInDOM2
1854020.9 Ops/sec
HTML Preparation code:
<div id="test-div"></div>
Script Preparation code:
function isInDOM1(oHTMLElement) { if (oHTMLElement === document.body || oHTMLElement === document ) { return true; } else { try { return document.body.contains(oHTMLElement); } catch(ex) { // Sometimes in Firefox element is anonymous div around input. // Throws error "TypeError: Argument 1 of Node.contains does not implement interface Node" // See https://bugzilla.mozilla.org/show_bug.cgi?id=208427 return false; } } } function isInDOM2(oHTMLElement) { var root = oHTMLElement.ownerDocument; if (!root) { return false; } if ( oHTMLElement.ownerDocument.documentElement === document.documentElement ){ return true; } return false; } var div = document.getElementById('test-div');
Tests:
isInDOM1
isInDOM1(div);
isInDOM2
isInDOM2(div);