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?
Edited my answer according to the first comment below this post.
Javascript
CSS
HTML
Output
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.