Julien Sazert Julien Sazert - 19 days ago 6
jQuery Question

Click back then next page in browser duplicates input

I have this js script where I append an input when document is ready :

$(document).ready(function() {
$('.mydiv').append('<p><input type="text" class="form-control" /></p>');
});


Problem is, when I click the previous page button in my browser then the next page button, the input appears twice.

Is there a way to 'reset' the script and make it run from scratch again when doing this manipulation ?

Thanks,

Answer

You need the html method. Try

$(document).ready(function() {
  $('.mydiv').html('<p><input type="text" class="form-control" /></p>');
});
Comments