#10 - Mostrar/Eliminar Elemento basado en Campo Personalizado

Comprueba si un miembro ha rellenado un campo personalizado. En caso afirmativo, establece el elemento de destino para mostrar.

Video Tutorial

Loom
tutorial.mov

Watch the video for step-by-step implementation instructions

The Code

32 lines
Paste this into Webflow
<!-- 馃挋 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>

Script Info

Versionv0.2
PublishedNov 11, 2025
Last UpdatedNov 11, 2025

Need Help?

Join our Slack community for support, questions, and script requests.

Join Slack Community
Back to All Scripts

Related Scripts

More scripts in Conditional Visibility