Hi there,
I just wondered how I could show/hide content based on an on/off switch field..
(without having to reload the page)
I have tried adding this code to the WP Admin Footer area in WPCodebox...
(I don't really know what i'm missing)
jQuery(function($) {
setTimeout(function () {
const $switch = $('input[name="is_framed"]');
const $framingOptions = $('.Framing-options');
function toggleFramingOptions() {
const isChecked = $switch.prop('checked');
console.log('Switch is checked:', isChecked); // debug
if (isChecked) {
$framingOptions.show();
} else {
$framingOptions.hide();
$framingOptions.find('input[type="checkbox"]').prop('checked', false);
}
}
toggleFramingOptions(); // run once on load
$switch.on('change', toggleFramingOptions); // run when changed
}, 300); // slight delay (adjust if needed)
});
Would appreciate any help anyone can give..
Oli