Julien Sazert Julien Sazert - 2 months ago 9
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 ?



You need the html method. Try

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