0
How to remove an element and clear the total window using JavaScript?
I use, getElementById() and removeChild() method for removing. But if I create more than one specific element with same id using JavaScript, then removeChild() removes only one block. I mean if I create 3 same elements with same id, how I remove all of these with one-click, like I refresh the page? removeChild() removes only one element with one-click.
10 Réponses
+ 3
Then for repeated elements, you should use class, not id.
+ 3
Here a sample to illustrate button click remove all same class elements.
https://code.sololearn.com/WX4mCJGyxEld/?ref=app
+ 2
Same id only allow to use once.
+ 2
First, for targeting more elements at once use class instead if id.
+ 1
Here is my code! Give some inputs and click the 'ok' button 2 or 3 times, and then click the 'reset' button...This is my problem. And the problem still persists.
Calviղ TheCoder | Yep, that's me Maneren thanks friends, for helping me 😊😊😊
https://code.sololearn.com/WOb0w15Qcksb/?ref=app
0
TheCoder | Yep, that's me Thanks for helping me ☺️. But sorry to say that, it doesn't solve my problem. I did exactly what they told to do. I think you can't understand my question or you can elaborate me with more simplicity! Please, pardon me.
0
Calviղ I have a form and when I clicked 'submit', it gives me a result within a html element, which is created by JS (by createElement() method with an id). If clicked 'submit' 3 times, it gives me same result 3 times and with the same id, because it is made by the same createElement() method.
But, I want to remove id as well as the element with just one-click.
I have to click 'reset' button 3 times to get a fully refreshed page (here I use removeChild() method in the reset function)
0
I used your method but it gives me error!Maneren