jQuery.html 返回子元素,而不是选定的元素

时间:2021-03-10 17:52:24

标签: javascript html jquery

我想从 HTML 中的一个元素获取整个 HTML,我这样做:

UserSchema.pre('updateOne', async function (done) {
  const hashedPassword = await Password.hash(this.get('password'));
  this.set('password', hashedPassword);

  done(null);
});

const divider = $('#divider').html()
$('#htmlElement').innerHTML = divider

但它返回 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="divider"> <span>Test</span> </div> <span id="htmlElement"></span> 中的 children 元素,而不是由 id 选择的整个 HTML。

如何使用 jQuery 从所选元素中获取整个 HTML 文本?包括他的类和所有内联样式?

0 个答案:

没有答案