• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript It works on Codepen, but doesn't work on google console..

Elindo

Coder
So, I got a code for add and remove fieldsets from a from.

The code works great on codepen, but when I got testes on vscode with the google console, well it doesn't work!!!

On codepen I can add and remove elements, but once I take it to the Google console it doesn't response to elements that have been deleted and I can't add it back on.


Even if the element exist in the html file, once it doesn't show in the screen, then the element seems to be lost and the code can't find it in Google console...... not the case in Codepen.io , even if the item is removed from the screen, the code can still find it and add it back on.

Check out these two functions... why would this code work in Codepen, but not Google Console?


Code:
const f2parent = document.getElementById ("parentfieldset");
const f22pump = document.getElementById ("fieldsetpump2");
const f23pump = document.getElementById ("fieldsetpump3");


const remove2pump = f2parent.removeChild(f22pump);
const remove3pump = f2parent.removeChild(f23pump);
const add2pump = f2parent.appendChild(remove2pump);
const add3pump = f2parent.appendChild(remove3pump);






function singlePumpf (){
  if(document.getElementById ("pump1").checked) {
 f2parent.removeChild(f22pump);
 f2parent.removeChild(f23pump);
    
  }
}


 function doublePumpf(){
if(document.getElementById ("pump2").checked) {   


  const f2parent = document.getElementById ("parentfieldset");
  const f22pump = document.getElementById ("fieldsetpump2");
  const f23pump = document.getElementById ("fieldsetpump3")
  f2parent.appendChild(remove2pump);
  f2parent.removeChild(f23pump);
 

New Threads

Latest posts

Buy us a coffee!

300x250
Top Bottom