У нас вы можете посмотреть бесплатно How to Hide Elements with Empty innerHTML in JavaScript and jQuery или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Learn how to easily check for empty `innerHTML` in a specific class in JavaScript or jQuery by dynamically hiding elements based on their content. --- This video is based on the question https://stackoverflow.com/q/74834705/ asked by the user 'Nikatia' ( https://stackoverflow.com/u/20469299/ ) and on the answer https://stackoverflow.com/a/74834756/ provided by the user 'T.J. Crowder' ( https://stackoverflow.com/u/157247/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Find if classes child class has empty innerHTML in javascript/jquery Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- Introduction If you've ever worked with HTML and JavaScript, you may have encountered the need to conditionally display elements based on their content. A common scenario is hiding child elements when they contain no visible text or HTML. In this guide, we will explore how to find if a child class has an empty innerHTML and how to hide its parent elements accordingly. In our example, we have a nested HTML structure. We want to display only those divs with content and hide those that are empty. Let’s break down how to achieve this using JavaScript. The Problem Consider the following HTML structure: [[See Video to Reveal this Text or Code Snippet]] In this HTML, each .middle-div contains a .small-div. We want to hide any .middle-div whose .small-div is empty. This means "Child 3" should not be displayed because it contains an empty div. The Solution To achieve this, we can use JavaScript's querySelectorAll to select all the .small-div elements within our # big-div. We will then iterate through these elements to check if they are empty. Step-by-Step Implementation Select All Small Divs: We first need to access all .small-div elements. [[See Video to Reveal this Text or Code Snippet]] Check for Empty Content: For each selected .small-div, we need to check if it has any child nodes. If it doesn't, we will hide its corresponding .middle-div. [[See Video to Reveal this Text or Code Snippet]] Adding CSS for Hidden Elements: We also need a simple CSS class to hide the elements we've marked. You can add the following styles in your CSS file: [[See Video to Reveal this Text or Code Snippet]] Full Example Here’s the complete example that will hide empty .middle-div elements after a timeout of 800 milliseconds: [[See Video to Reveal this Text or Code Snippet]] Allowing for Whitespace If you want to consider a div with just whitespace as empty, modify the condition slightly: [[See Video to Reveal this Text or Code Snippet]] This way, any .small-div containing only whitespace will also hide its parent .middle-div. Conclusion In this post, we learned how to easily check for empty innerHTML in a specific class in JavaScript and hide its parent elements accordingly. Using this approach allows for cleaner, more dynamic web applications by ensuring only content-rich sections are displayed. Whether you're just getting started with JavaScript or you're an experienced developer, understanding how to manipulate the DOM based on content can greatly enhance your applications and user experience. Feel free to explore and modify the provided code snippets in your own projects!