From 258b26b334af41670e9fe2b35f5d5ce6a5e5bcf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= <188768+fb55@users.noreply.github.com> Date: Tue, 8 Jun 2021 12:26:13 +0100 Subject: [PATCH] fix(manipulation): `.html` should move passed nodes (#1923) Fixes #940. --- src/api/manipulation.spec.ts | 7 +++++++ src/api/manipulation.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api/manipulation.spec.ts b/src/api/manipulation.spec.ts index 787d5be208..c3134222fe 100644 --- a/src/api/manipulation.spec.ts +++ b/src/api/manipulation.spec.ts @@ -1770,6 +1770,13 @@ describe('$(...)', () => { expect(html).toBe('
  • Durian
  • '); }); + it('(elem) : should move the passed element (#940)', () => { + $('.apple').html($('.orange')); + expect($fruits.html()).toBe( + '
  • Orange
  • Pear
  • ' + ); + }); + it('() : should allow element reinsertion', () => { const $children = $fruits.children(); diff --git a/src/api/manipulation.ts b/src/api/manipulation.ts index 6d2656fe0b..74a7719ebc 100644 --- a/src/api/manipulation.ts +++ b/src/api/manipulation.ts @@ -939,7 +939,7 @@ export function html( opts.context = el; const content = isCheerio(str) - ? str.clone().get() + ? str.toArray() : parse(`${str}`, opts, false).children; updateDOM(content, el);