Retrieving native DOM elements from jQuery objects?

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

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

5条回答
  •  鱼传尺愫
    2021-01-04 03:47

    Other people have already directly answered the question. Use the get() method.

    However, most of the time you want to use jQuery methods to do the manipulation as opposed to getting access to the raw DOM element and then modifying it using "standard" JavaScript.

    For example, with jQuery you can just say $('mySelector').addClass('myClass') to add a CSS class to a DOM element. This is much more complicated (and browser specific) using direct DOM manipulation. This concept extends to almost every other DOM manipulation you would care to do.

提交回复
热议问题