What's the difference between .clone() and .html()?

前端 未结 5 539
广开言路
广开言路 2021-02-05 15:03

What is the difference between Jquery\'s .clone() and .html() functions?

Jquery documentation states:

The .clone() method performs a deep copy of

5条回答
  •  既然无缘
    2021-02-05 15:57

    The clone() method will copy the data and events associated with the DOM elements that are copied, this method returns a jQuery object of the target. html() is just the string representation of the DOM, which means that none of the events/data associated with that portion of the DOM will be copied, this method returns just a string.

    Edit #2 Removed my comments about clone() being just as fast as html(), it is actually slower. Examples can be seen below in Casey Falk's comments.

提交回复
热议问题