Many thanks to cdnjs for hosting this script. Following an example on how to include it.
<script src="//cdnjs.cloudflare.com/ajax/libs/dom4/1.8.3/dom4.js" >/* DOM4 */</script>
And for new DOM Level 4 childNode entries:
- Element#replaceWith() ( warning Element#replace() has been recently deprecated )
The implemented test is conform to current specifications.
Other fixes/standardized behaviors include:
- new DOM Listener: capture, passive, and once
- fully normalized
MouseEventand the latest way to create
Elements as Array subclass, so that
el.queryis the relative equivalent of
el.queryAllis the relative equivalent of
Array.prototype.slice.call(el.querySelectorAll(css)). Relative means
node.query('body p')won't return any
pelement contained in
node, while old
document.queryAll(css) returns an Array so there's no need to use
queryAllfor a list or
queryto get one element. We can forget the
- classList, with forced fixes for iOS 5.1 and Nokia ASHA Xpress Browser and early implementations
- CustomEvent constructor for all browsers down to IE8
- Element#matches utility to test elements against CSS selectors
- Element#closest utility to find element inclusive ancestor via CSS selectors
- Node#contains utility to know if another node is inside the current one
cancelAnimationFrameare polyfilled too but the least legacy fallback to setTimeout does not support accurate timing and doesn't slow down execution with that logic. Feel free to load upfront other polyfills if needed.
The DOM4 license is Mit Style.
If you need other polyfills too have a look at another DOM-shim repo.
Theoretically compatible with all browsers you know that are truly used these days, here a list:
- Android 2.1+
- Safari Mobile since iOS 3.0 and Desktop
- Opera Mobile, Mini, and Desktop
- Blackberry 7.1 and higher
- Samsung Bada 2 native Browser
- Midori and most likely all other WebKit based
- Chrome Mobile and Desktop
- Firefox Mobile and Desktop
- IE8+ for Desktop and IE Mobile 9 or greater.
- Nokia Xpress Browser for ASHA Platform
- Silk Browser - Fire OS 3.0
- PhantomJS can benefit from DOM4 too
It's way easier if you tell me which browser in a current relevant market share is not supported :-)
For IE8 only it's recommended to include ie8 script before
dispatchEvent won't work as expected.