同意カテゴリーに基づいたDIVを表示又は非表示にする
あるカテゴリーのクッキーが受け入れられたり受け入れられなかったりしたときに、表示したり隠したりしたいコンテンツがあるとします。その場合には、次の例を使用できます。
まず、divにクラスが割り当てられていることを確認してください。以下の例は、広告カテゴリとtestdivというdivを使用しています。
<script>
function callbackFnc(e) {
var consent = e.detail || null;
var elements = document.querySelectorAll(".testdiv");
elements.forEach(function(el) {
// no consent yet or advertising not accepted, hide div
if (!consent || !consent.advertising) {
el.style.display = 'none';
} else {
el.style.display = 'block';
}
});
}
window.addEventListener("cf_consent", callbackFnc);
window.addEventListener("cf_consent_loaded", callbackFnc);
</script>


