Home >Web Front-end >CSS Tutorial >How Can I Clear a Div\'s Content Using JavaScript?
Clearing Div Content with JavaScript
To dynamically remove the content of a div element when a user clicks a button, JavaScript offers an efficient solution.
Answer:
Using Pure JavaScript:
function clearBox(elementID) { document.getElementById(elementID).innerHTML = ""; }
<button onclick="clearBox('cart_item')">Clear Div</button>
Using jQuery (for comparison):
$("#cart_item").html("");
The above is the detailed content of How Can I Clear a Div\'s Content Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!