I have a set of DOM elements that I want to show only when a controlling checkbox is checked by the user. All of these items have a common class and are initially hidden:
.spec { display:none; }
In the click handler of the checkbox, I originally had the following, which worked fine for existing elements. However, the tables are dynamically generated via AJAX, and when new elements are added with the "spec" class, they are not displayed when the checkbox is checked.
// Basic jQuery show/hide
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 to the DOM. But in general, that may not be true, so my question is:
What is the normal jQuery way to address this issue?
Since the jQuery show/hide functions alter the element.style and not the style object itself, I ended up writing a jQuery plugin that alters the stylesheet, which works fine, but seems like over kill, hence the question.
var nval = btn.checked ? '' : 'none';
$.styleSheet('.spec', 'display', nval );