Possible Duplicate:
How do I clear the text contents of a div in javascript?
Im actually making a web based terminal. I have a few ideas that I want to implement.
I have a textbox, upon typing in 'clear' into the texbox and pressing enter. T开发者_JS百科he contents of the div should be cleared. The div tag here just shows the output, and i want to be able to clear it.
I have actually made the textbox, and it is accepting input such as -ls that shows the output on the browser.
Something like that:
Suppose html is:
<input type="text" id="text" />
<div id="c">
Contents here
</div>
The javascript would be:
$("#text").keyup(function(e){
if(e.keyCode == 13){
if($(this).val() == "cls"){
$("#c").empty();
}
}
});
I'm not sure I understand your question. What about $("#terminal").empty()?
http://api.jquery.com/empty/
You can use the empty() method:
$("#yourDivId").empty();
Or you can pass an empty string to the html() method:
$("#yourDivId").html("");
精彩评论