I'm taking someone else's jquery code and trying to add the functionality into my own application in plain JS. I've encountered something that I can't figure out, it's clearly taking a DOM element, removing it, and cloning it to add back in. The jquery starts with this variable declaration:
const template = $('#template').remove().removeAttr('id').removeAttr('style');
and the element in the html looks like this...
<p id="template" style="display: none;">
when I console log the element in the jquery it gives me an object like this 'w.fn.init [p]', which I'm guessing is just the jquery p element. I'm not sure why the 'removeAttr' are chained on to the initial remove, obvs to turn the display on and off but not sure why this is important if you're removing the element. template.parentNode.removeChild(template)
doesn't recreate it.
The template variable is then used in a function in the jquery like this.....
const clone = template.clone();
const input = clone.find('.p-input');
which, obviously, is cloning the element in order to use it. I tried:
let clone = document.getElementById('template').cloneNode();
but that seems to just clone the element without the contents, so when I try and find the '.p-input' I get null. How would I recreate this in plain js?