I’m still searching for a solution to hide an element if there is no content found in that element.
I’m using Custom fields that are dynamically populating a custom post type via global block (not sure if I said that correctly).
But anyway, if nothing is entered into a CPT field, then I want that element hidden on the page. Here is the different snippets of code that I’ve tried to use in the JS area of the Global Block:
jQuery(document).ready(function($) {
if ( $(".x-quote-text").html() == “”){
$(".x-quote").addClass(“visuallyhidden”);
}
});
jQuery(document).ready(function($) {
str = $(’.x-quote-text’).text();
if($.trim(str) === “”) {
$( “.x-quote” ).empty();
}
});
jQuery(document).ready(function($) {
if ( $(".x-quote-text").text().length == 0 )
$(".x-quote").addClass(“visuallyhidden”);
}
});
jQuery(document).ready(function($) {
str = $(‘div.x-quote-text’).text();
if($.trim(str) === “”) {
$(‘blockquote.x-quote’).visuallyhidden();
}
});
And of course I added the CSS for the .visuallyhidden {display: none;}
None of this worked.
Any ideas?