According to DOM level 4 specs, which is the current version in development, there are some new handy mutation methods available:
The bulletproof way
Assuming we have the following HTML element:
The jQuery way
The new way. FTW.
Having already defined the variable
elem, here’s how to properly remove that node:
Notice the jQuery similarity? This new way is simpler and much more intuitive… for the win.
At this time, the support is: Chrome, Opera, Safari and soon Firefox 23. Maybe it’s not so awesome for production purposes, but still great for testing and debugging.
However, if you’re looking for larger browser support, there are some polyfills that definitely worth an eye on:
Besides these new methods, don’t forget about the