Clearing Div Content with JavaScript
To remove the content from a div when a user clicks a button, follow these steps:
Creating the Clear Function
function clearBox(elementID) { document.getElementById(elementID).innerHTML = ""; }
Connecting the Button
<button onclick="clearBox('div_id')">Clear Div</button>
Replace div_id with the actual ID of the div you want to clear.
jQuery Example (Optional)
$('#div_id').html("");
By following these steps, you can easily clear the content of a div when a button is clicked, allowing for dynamic interaction with your web page.
The above is the detailed content of How Can I Clear a Div\'s Content with JavaScript on Button Click?. For more information, please follow other related articles on the PHP Chinese website!