<div class='item'> <p>Askoll M239 (M231)</p> </div> 

How can I clear the contents of the .item file in the 1.html file, that is, delete the <p>Askoll M239 (M231)</p> file?

  • by clicking on what? - humster_spb
  • on button <button> - Andrey Povkh

1 answer 1

In the most general form - something like that. But this is pure js - php and ajax are not used here. Perhaps you had something else in mind?

 let item = document.querySelector('.item'); let child = document.querySelector('p'); let button = document.querySelector('button'); button.onclick = function() { item.removeChild(child); } 
 <div class='item'> <p>Askoll M239 (M231)</p> </div> <br /> <button>очистить по клику</button> 

  • Should be removed on the server side, not the client. Is it hard to implement? - Andrey Povkh
  • @ NatalyaTsvіgun, well, yes, it will probably be more difficult: you need to send a task to the server by clicking on the client so that the php script reads the 1.html file, finds a specific div with a specific content and deletes it - the logic is something like humster_spb