开发者

empty contents of a div tag based on user input using jQuery [duplicate]

开发者 https://www.devze.com 2023-02-25 05:01 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: How do I clear the text contents of a div in javascript?
This question already has an answer here: Closed 11 years ago.

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("");
0

精彩评论

暂无评论...
验证码 换一张
取 消