Jquery load function behavior on reload -


in index.php load page content jquery load function. access elements loaded use load callback function.

this scenario

index.php

<html>.. <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script> <script type="text/javascript" src="js/script.js"></script>  <div id="load-page"></div>  <button type="button" class="btn btn-primary" id="reload">     <span class="glyphicon glyphicon-refresh"></span> reload </button> <button type="button" class="btn btn-default" id="selectall">     <span class="glyphicon glyphicon-check"></span> select </button> <button type="button" class="btn btn-default" id="add">     <span class="glyphicon glyphicon-plus"></span> add </button> 

loaded-page.php

<input type="checkbox" name="chbox[]" value="1" /> <input type="checkbox" name="chbox[]" value="2" /> <input type="checkbox" name="chbox[]" value="3" /> <input type="checkbox" name="chbox[]" value="4" /> 

script.js

$(function() {      var loadpage = function () {          $('#load-page').load('loaded-page.php', function() {              $('#selectall').on('click', function(){                 $('input[name="chbox[]"]').prop('checked', true);                 console.log($(this).html());             });              $('#reload').on('click', function(){                 loadpage();             });              $('#add').on('click', function(){                 $.ajax({                     type: "post",                     url: add.php,                     success: function(data) {                         loadpage();                     }                 });             });          });     }      loadpage(); // load page when dom ready  }); 

everything seemed work fine, noticed @ startup (first load), if click "select all" button console display

<span class="glyphicon glyphicon-checked"></span> select 

after first load if re-load (reload or add) , click "select all" button console display

<span class="glyphicon glyphicon-unchecked"></span> select <span class="glyphicon glyphicon-unchecked"></span> select 

if still re-load (reload or add) , click "select all" button console display

<span class="glyphicon glyphicon-unchecked"></span> select <span class="glyphicon glyphicon-unchecked"></span> select <span class="glyphicon glyphicon-unchecked"></span> select 

and on..

how do? thank you


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -