)
Is it possible to hide the text "Produktgrundpreis (falls vorhanden):" when the sibling child div is empty? View current site layout here
Here is the structure of the DOM: Structure
<div id="Produktgrundpreis-Text" class="brz-css-kfrku brz-css-iwlmt brz-wrapper">
<div class="brz-rich-text brz-css-psnqi" data-custom-id="nvnuscfnezabbinlagscfvcigqzzhejoypkb">
<div>
<p class="brz-css-zpfqz" data-uniq-id="wuxnq" data-generated-css="brz-css-vtvig">
<span class="brz-cp-color7">Produktgrundpreis (falls vorhanden):</span>
</p>
</div>
</div>
</div>
<div id="Produktgrundpreis-Shortcode" class="brz-css-kfrku brz-css-eburp brz-wrapper">
<div class="brz-wp-shortcode brz-css-fciet" data-custom-id="xfbqskiqkijowmwcilpwfpsdgetytiwoqvto">
<div>
</div>
</div>
</div>
Being a beginner in JS, I attempted to write this code on my own:
function pgpVisibility() {
var pgpShortcode = document.getElementById('Produktgrundpreis-Shortcode').innerText;
console.log(pgpShortcode)
if (pgpShortcode.includes('')) {
document.getElementById('Produktgrundpreis-Text').style.display = "none";
}
}
Since the content of Produktgrundpreis-Shortcode is empty, I assumed I could use .innerText to achieve this. What improvements can be made?