Best practice for using DOM Level 0 in modern JavaScript applications

后端 未结 5 1402
一整个雨季
一整个雨季 2021-02-01 04:55

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

5条回答
  •  一向
    一向 (楼主)
    2021-02-01 05:53

    In jQuery-using applications, 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 dom0 collections are best avoided, or because jQuery makes it much easier to change the underlying DOM structure?

    That can be explained quite easily. 95% of jQuery developers are ignorant of the fact the DOM API exists or can be used.

    The fact that jQuery is abused for things the DOM can do more easily is simply caused by people not learning the DOM.

    Personally I'd say use DOM 0, but then again, personally I would say use a DOM shim and don't use jQuery. It's all a matter of choice.

    Do whatever is the most maintainable

提交回复
热议问题