Julien Sazert Julien Sazert - 1 year ago 79
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 ?


Answer Source

You need the html method. Try

$(document).ready(function() {
  $('.mydiv').html('<p><input type="text" class="form-control" /></p>');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download