0

My requirement is after clicking on some button, I need to create a new and replace element something we do with DOM manipulation such as createElement,replaceChild. How we can achieve this with the combination of vanilla JS and Node Js?

Based on here and here I know DOCUMENT is not supported in NodeJs, but how I have to do below code with the help of Node and JS?

I am trying to replace below label with another element but not sure how to achieve this using nodejs.

<label id="task1Status" class="progressDiv progress">Yet to Start</label>

with below JS code,

let loadingE=document.createElement('div');
console.error("replace1");
loadingE.className='lds-ellipsis';
let loadingE1=document.createElement('div');
let loadingE2=document.createElement('div');
let loadingE3=document.createElement('div');
let loadingE4=document.createElement('div');
loadingE.appendChild(loadingE1);
loadingE.appendChild(loadingE2);
loadingE.appendChild(loadingE3);
loadingE.appendChild(loadingE4);
OldE=document.getElementById('task1Status');
document.getElementById('divTask1Status').replaceChild(loadingE,OldE);
Dale K
  • 25,246
  • 15
  • 42
  • 71
J_Coder
  • 707
  • 5
  • 14
  • 32
  • NodeJS is a server-side language. It doesn't have the `window` property, because it is not contained within a window. NodeJS is normally contained within a `module`. To achieve such behavior, which I believe takes place solely on the client-side, you should use pure JavaScript – fingeron Jan 21 '20 at 02:45
  • If you need to do server-side html manipulation you would need to use a library like JSDOM that can parse html and provide dom manipulation api – Patrick Evans Jan 21 '20 at 02:46
  • @PatrickEvans I think he's talking about DOM manipulation after page load. – fingeron Jan 21 '20 at 02:53

0 Answers0