I have a set of DOM elements that I want to show only when the checkbox is set by the user. All these elements have a common class and are initially hidden:
.spec { display:none; }
In the checkbox click handler, I initially had the following: which worked fine for existing elements. However, tables are dynamically generated via AJAX, and when new items are added with the class "spec", they are not displayed when the checkbox is selected.
if (btn.checked)
$('.spec').show();
else
$('.spec').hide();
Since in my case this is in the same JS module, I could always just re-execute this code after adding it to the DOM. But overall this may not be true, so my question is:
What is the normal jQuery way to solve this problem?
show/hide jQuery element.style,
, jQuery,
stylesheet, , , , .
var nval = btn.checked ? '' : 'none';
$.styleSheet('.spec', 'display', nval );