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
Post a Comment