asp.net - jQuery how to use variables -


the code below working

$(function () {     $('.bigdiv input:checkbox').click(function () {         alert('working');     }); }); 

but 1 not working

var checkboxes = $('.bigdiv input:checkbox'); $(function () {     checkboxes.click(function () {         alert('working');     }); }); 

chances have put line:

var checkboxes = $('.bigdiv input:checkbox'); 

inside $(function () { block document ready before run previous line of code. if document isn't done loading, there won't checkboxes find. point of $(function () { /* code here */}); wait until document done loading before running code in callback function.

you should able this:

$(function () {     var checkboxes = $('.bigdiv input:checkbox');     checkboxes.click(function () {         alert('working');     }); }); 

or alternately, put code in script tag @ end of body , not need ready handler:

var checkboxes = $('.bigdiv input:checkbox'); checkboxes.click(function () {     alert('working'); }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -