Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:58:23+00:00 2026-06-13T05:58:23+00:00

Say an HTML file is purposely arranged to display a simple vertical layout so

  • 0

Say an HTML file is purposely arranged to display a simple vertical layout so that I see a vertical arrangement of elements when the browser renders it. So there are no elements right or left one to another.
Now, for layout purposes, there are various other elements like < div> (for example) that are not displayed because they just are useful for CSS or the structure. That is, just elements like < p>, < img> and other text nodes have something displayed (spacing and color areas are not important).
I would like to ask here if it is possible (using javascript on the DOM) to have an array populated wiht just the elements that display something when rendered.
For example, say I have

< div class="div1class">  
< div class="div2class">  
< p>
some text here  
< img src="img.jpg"/>  
some text here too
< /p>  
< /div>  
< div class="div3class"> <img src="img2.jpg"/> < /div>  
< /div>   

The array would be in this case:

0 text node  
1 img  
2 text node  
3 img  

How to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:58:24+00:00Added an answer on June 13, 2026 at 5:58 am

    Edited my answer according to the first comment below this post.

    Javascript

        var nodeTypes = [];
    
        function getContent(elm) {
            if (elm.nodeType != 1 && elm.nodeType != 3) return;
            // skip if it's not an element or text node
            if (elm.nodeType == 1) { // element
                var comp = window.getComputedStyle(elm,null);
                var disp = comp.getPropertyValue('display') != 'none';
                var hidden = comp.getPropertyValue('visibility') == 'hidden';
                if (!disp || hidden) return;
                // skip if it's hidden
                if (elm.childNodes.length) {
                    for (var i = 0; i < elm.childNodes.length; i++)
                        getContent(elm.childNodes[i]);
                    return;
                }
            }
            if (/^\s+$/.test(elm.nodeValue)) return;
            // skip if it's empty
            nodeTypes.push((elm.nodeType == 3 ? 'text node' : elm.nodeName).toLowerCase());
        }
    
    </script>
    

    CSS

    <style type="text/css">
        a span {display:none;}
    </style>
    

    HTML

    <body>
        <div class="div1class">
            <div class="div2class">
                <p>
                    some text here
                    <img src="img.jpg" />
                    some text here too
                </p>
            </div>
            <div>
                <a href="#">Anchor example<span>hidden element</span></a>
            </div>
            <!-- some comment -->
            <div class="div3class"><img src="img2.jpg" /></div>
        </div>
        <script type="text/javascript">
            nodeTypes = [];
            getContent(document.getElementsByClassName('div1class')[0]);
            console.log(nodeTypes);
        </script>
    </body>
    

    Output

    ["text node", "img", "text node", "text node", "img"]

    You will need to take many possibilities into consideration, such as an element that might look empty in code but actually has a background image. Using jQuery this would be much more reliable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say a user visits the page http://somedomain.com/path/file.html#foo , I'd like to display, using JavaScript,
Say, an HTML file contains the following elements: <div class=mydiv> <img src=img.jpg/> </div> I
Say I have an html file that I have loaded, I run this query:
I have an HTML file that contain iframe, say (called a.html): <body> <iframe width=430
Say i have a .html file that contains a web design and has variables
Let's Say i have a HTML file with that structure <html> <head> </head> <body>
Say i have a file test.html that uses javascript cookies. (a) When i access
Lets say i have a html file that contain a form: <form method=post action=url>
Say, I've got an HTML file that I want to process using Javascript. For
lets say that we are studding a url string: http:/domain.com/en/#the-file.html/section-4 where i have codified:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.