0

I am using an .append every time I click a button.

 $( ".kop_filters" ).append( "<p class='gekozen_datum'>Gekozen datum: </p>" );

If I click the button 4 times this is appending in my page like:

Gekozen datum:
Gekozen datum:
Gekozen datum:
Gekozen datum:

I want it to appear once and every time I click it removes and append again so for example after a couple of times clicking on it I have printed it once. It is because I want to load a variable in it which change every time on click.

EDIT: Found the solution here: Ajax replace instead of append

JacobHout
  • 31
  • 1
  • 7
  • Found solution here: https://stackoverflow.com/questions/1675215/ajax-replace-instead-of-append – JacobHout Feb 21 '19 at 12:43
  • Possible duplicate of [Ajax replace instead of append](https://stackoverflow.com/questions/1675215/ajax-replace-instead-of-append) – empiric Feb 21 '19 at 12:52

2 Answers2

0

Use the html method.

$('button').click(() => {
  $(".kop_filters").html((Math.random() * 10).toString())
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="kop_filters"></div>
<button>Update</button>
James Coyle
  • 9,922
  • 1
  • 40
  • 48
0

Hii @JacobHout you can use jQuery empty() function like this

  $( ".kop_filters" ).empty();

this will definitely help you :)

Videsh Chauhan
  • 371
  • 2
  • 18