Reputation:
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>
Upvotes: 6
Views: 4261
Reputation: 5396
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.com/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>
Upvotes: 1
Reputation: 31
$('#display').html("");
Here is the working fiddle example.
https://fiddle.jshell.net/75fLkhmz/
Upvotes: 0
Reputation: 21
Try using simple javascript
document.getElementById('display').innerHTML ="";
Hope this helps.
Upvotes: 2
Reputation: 1329
If you are using jquery then use:
<script>
$( "#display" ).empty();
</script>
Make sure you are loading jquery.
Upvotes: 2