-4

What is the javascript equivalent for

$('#srcSelectorId').appendTo('#destSelectorId');

1 Answers1

-3

javascript dom equivalent for jquery appendTo is as the following lines of code:

srcEl = document.getElementById('srcSelectorId');
destEl = document.getElementById('destSelectorId');
destEl.appendChild(srcEl);
  • Why the `documentFragment`? Just do `destEl.append(srcEl)` and job done. – Niet the Dark Absol Nov 07 '21 at 23:26
  • Uh... So in your mind, `append`ing it to another element (somehow) *clones* it, but `append`ing it to a `DocumentFragment` works just fine? How does that make sense? `append`ing an element to another moves it, always. – Niet the Dark Absol Nov 08 '21 at 13:19
  • [jQuery docs](https://api.jquery.com/appendto/): "The `.append()` and `.appendTo()` methods perform the same task. The major difference is in the syntax" So they literally do the same thing, it's just that one is `target.append(source)` and the other is `source.appendTo(target)`. – Niet the Dark Absol Nov 08 '21 at 13:21
  • Well now you're just showing that you don't even understand how `.append()` works... – Niet the Dark Absol Nov 08 '21 at 14:20