When to use Vanilla JavaScript vs. jQuery?

后端 未结 13 2077
独厮守ぢ
独厮守ぢ 2020-11-22 09:08

I have noticed while monitoring/attempting to answer common jQuery questions, that there are certain practices using javascript, instead of jQuery, that actually enable you

13条回答
  •  不知归路
    2020-11-22 09:45

    The first answer's live properties list of this as a DOM element is quite complete.

    You may find also interesting to know some others.

    When this is the document :

    • this.forms to get an HTMLCollection of the current document forms,
    • this.anchors to get an HTMLCollection of all the HTMLAnchorElements with name being set,
    • this.links to get an HTMLCollection of all the HTMLAnchorElements with href being set,
    • this.images to get an HTMLCollection of all the HTMLImageElements
    • and the same with the deprecated applets as this.applets

    When you work with document.forms, document.forms[formNameOrId] gets the so named or identified form.

    When this is a form :

    • this[inputNameOrId] to get the so named or identified field

    When this is form field:

    • this.type to get the field type

    When learning jQuery selectors, we often skip learning already existing HTML elements properties, which are so fast to access.

提交回复
热议问题