Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for using DOM Level 0 in modern JavaScript applications

Tags:

People also ask

Is DOM manipulation important in JavaScript?

DOM manipulation is one of the most important things when writing JavaScript for web browsers. It should be one of the first things you learn when learning JavaScript language.

Which DOM method is supported by most browsers?

The last & final method is innerHTML, an interesting one. It's supported on mostly every browser or platform. However, it's a nonstandard element. Typically, it is used to access & write content inside XHTML elements.

What is DOM manipulation in JavaScript?

In website development, DOM stands for Document Object Model. It is a programming interface that allows us to create, change, or remove elements from a website document. DOM manipulation is when you use JavaScript to add, remove, and modify elements of a website. It is very common in web development.


Is there an agreed set of "best practices" for use of the DOM Level 0 collections in modern JavaScript applications? (document.forms, document.images, etc.)

In applications using jQuery, I've noticed a tendency to, say, change the contents of a drop-down using $(...).html() to switch out the underlying nodes, rather than using element.options[]. Is this because the DOM 0 collections are best avoided, or because jQuery makes it much easier to change the underlying DOM structure?

Edit: I guess part of the question includes if the older features are reliable cross-browser. I remember that, once upon a time, IE would add <tbody> tags automatically to your table, while firefox would not. That made walking the dom tree painful cross-browser. Similarly, element.options[] had problems when changing the options in the collection. Are these guys reliable cross-browser?