admin管理员组文章数量:1277566
Im using PRE tag of HTML and I need on click to clear the content of it, I've tried the following without success.
$('#display').clear;
$('#display').val("");
In the index html I use it like this
<pre id="display"></pre>
Im using PRE tag of HTML and I need on click to clear the content of it, I've tried the following without success.
$('#display').clear;
$('#display').val("");
In the index html I use it like this
<pre id="display"></pre>
Share
Improve this question
asked Feb 9, 2016 at 12:10
user4445419user4445419
3
-
1
tried
.html("")
or.text("")
– Jaromanda X Commented Feb 9, 2016 at 12:11 -
.empty()
too is there.....:) – Jai Commented Feb 9, 2016 at 12:13 - 1 If you are using any library/framework methods do try to see their documention first. It's easy to know what to expect from specific method. – Diljohn5741 Commented Feb 9, 2016 at 12:14
6 Answers
Reset to default 3Use html("")
to clear content
$('#display').html("");
If you are using jquery then use:
<script>
$( "#display" ).empty();
</script>
Make sure you are loading jquery.
Try using simple javascript
document.getElementById('display').innerHTML ="";
Hope this helps.
You used $('selector').val('')
and it is for input boxes, and won't work here!
I suggest you to use one of the bellow ways:
$(document).ready(function(){
$("#delete-1").click(function(){
$('#display1').html('');
});
$("#delete-2").click(function(){
document.getElementById('display2').innerHTML ="";
});
$("#delete-3").click(function(){
$('#display3').empty();
});
$("#delete-4").click(function(){
$('#display4').text('');
});
})
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="display1">
Here is pre content
</pre>
<br/>
<pre id="display2">
Here is pre content
</pre>
<br/>
<pre id="display3">
Here is pre content
</pre>
<br/>
<pre id="display4">
Here is pre content
</pre>
<br/>
<a id="delete-1" href="#">Delete #1</a>
<a id="delete-2" href="#">Delete #2</a>
<a id="delete-3" href="#">Delete #3</a>
<a id="delete-4" href="#">Delete #4</a>
this clear the data between the tag
$('#display').text('');
$('#display').html("");
Here is the working fiddle example.
https://fiddle.jshell/75fLkhmz/
本文标签: javascriptHow to clear pre tag in htmlStack Overflow
版权声明:本文标题:javascript - How to clear pre tag in html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741230482a2362015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论