Retrieving native DOM elements from jQuery objects?

后端 未结 5 1273
谎友^
谎友^ 2021-01-04 03:10

How can I get jQuery to return the native DOM elements it encapsulates?

5条回答
  •  轮回少年
    2021-01-04 04:01

    When you find elements with jQuery, you can get them with the "get" function:

    var regularElement = $('#myElementId').get(0);
    

    Inside a ".each()" function, the "this" pointer refers to a "real" element:

    $('input.special').each(function() {
      var type = this.type;
      this.value = "exploding balloon";
      // etc
    })
    

    Using jQuery doesn't make Javascript "different." It is Javascript, and the DOM is still the DOM.

提交回复
热议问题