javascript - Click Not Firing on Button -


i have html button hooked jquery function @ top of page, click not seem firing? there i'm missing?

$(function(){                 $('#ctl00_content_hidepast').click(function() {                     var dt = new date($.now() - 30 * 60000);                     var time = dt.gethours() + ":" + dt.getminutes() + ":" + dt.getseconds();                     $("td.bgtime").each(function() {                         var bookingtime = ($(this).text().split(':'));                         var d = new date();                         d.sethours(+bookingtime[0]);                         d.setminutes(bookingtime[1]);                          var state = $("#ctl00_content_hdnpastbookingtoggle").val();                          if ($(d) > time) {                             var timerow = $(this).parent();                             $(timerow).toggle("slow",                                 function() {                                     if (state.val === "0") {                                         state.val = "1";}                                      else if (state.val === "1") {                                         state.val = "0";                                     };                                 });                         };                     });                 });             }); 

and button:

<button id="ctl00_content_hidepast"><i class='fa fa-eye-slash'></i> hide/show past bookings</button> 

try

$(function(){                 $(document).on('click','#ctl00_content_hidepast', function() {                     var dt = new date($.now() - 30 * 60000);                     var time = dt.gethours() + ":" + dt.getminutes() + ":" + dt.getseconds();                     $("td.bgtime").each(function() {                         var bookingtime = ($(this).text().split(':'));                         var d = new date();                         d.sethours(+bookingtime[0]);                         d.setminutes(bookingtime[1]);                          var state = $("#ctl00_content_hdnpastbookingtoggle").val();                          if ($(d) > time) {                             var timerow = $(this).parent();                             $(timerow).toggle("slow",                                 function() {                                     if (state.val === "0") {                                         state.val = "1";}                                      else if (state.val === "1") {                                         state.val = "0";                                     };                                 });                         };                     });                 });             }); 

in case bind event document. used when have dynamic dom elements. don't need bind click event document. it's recommended attach non dynamic parent. example div contain buttons. in case code be:

  $(document).on('click','div contains buttons selector', function() .. 

it makes things lighter. since don't have dom structure gave answer work in case.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -