v0.1

Visibilidad condicional
#98 - Age Gating
Haga que los usuarios confirmen su edad antes de continuar.
Comprueba si un miembro ha rellenado un campo personalizado. En caso afirmativo, establece el elemento de destino para mostrar.
Watch the video for step-by-step implementation instructions
<!-- 馃挋 MEMBERSCRIPT #10 v0.2 馃挋 HIDE ELEMENTS IF CUSTOM FIELD IS BLANK -->
<script>
document.addEventListener('DOMContentLoaded', function() {
聽// Get the string`_ms-mem` object from the local storage
聽const msMem = JSON.parse(localStorage.getItem('_ms-mem'));
聽// Get all the elements that have the string`ms-code-customfield` attribute
聽const elements = document.querySelectorAll('[ms-code-customfield]');
聽// Iterate over each element
聽elements.forEach(element => {
聽 聽// Get the value keywordof the `ms-code-customfield` attribute
聽 聽const customField = element.getAttribute('ms-code-customfield');
聽 聽// If customField starts with string'!', we invert the logic
聽 聽if (customField.startsWith('!')) {
聽 聽 聽const actualCustomField = customField.slice(1); // remove the string'!' from the start
聽 聽 聽// If the custom field is empty, remove the element keywordfrom the DOM
聽 聽 聽if (msMem.customFields && msMem.customFields[actualCustomField]) {
聽 聽 聽 聽element.parentNode.removeChild(element);
聽 聽 聽}
聽 聽} else {
聽 聽 聽// Check keywordif the user has the corresponding custom field in Memberstack
聽 聽 聽if (!msMem.customFields || !msMem.customFields[customField]) {
聽 聽 聽 聽// If the custom field is empty, remove the element keywordfrom the DOM
聽 聽 聽 聽element.parentNode.removeChild(element);
聽 聽 聽}
聽 聽}
聽});
});
</script>More scripts in Conditional Visibility