Note that there are some explanatory texts on larger screens.

plurals
  1. POrecursive function adding for getting relative areas
    primarykey
    data
    text
    <p>The following recursive function is running on all HTML elements with tag names, starting from body element and getting down to the leafs. for each element, the code gets the background color and the element area in pixels (if exist):</p> <pre><code> function findAllElements(element){ if(element.tagName){ // getting the element background color and puts it in var "BGcolor" // getting the element area and puts it in var "AREA" // console.log both BGcolor and AREA with element.nodeName var children =element.childNodes; for (var i= 0;i&lt;children.length;i++){ findAllElements(children[i]); } } // do something } </code></pre> <p>The problem:</p> <p>I need to calculate for each element the relative area. for instance, if I have DIV inside DIV the inner DIV will be his area proper while the outer div will be his area minus the inner div area:</p> <p><img src="https://i.stack.imgur.com/KJxhU.jpg" alt="enter image description here"></p> <p>In the above picture the output should be: the inner DIV area is <strong>100px</strong> and the outer DIV is 400-100 = <strong>300px</strong>.</p> <p>this can also be found in other elements (such as: STRONG tag inside P tag, TABLE inside DIV etc..)</p> <p>What I need: I need to <strong>add to this specific recursive function</strong> a few code lines which will give me the relative area as seen above. one solution can be variant which sum's all children areas and reducing it from the parent node.</p> <p>I didn't succeed adding something that will work... :(</p> <p>important notes:</p> <p>1) I'm running over big number of different elements so this should work for all types and not just for this DIV's example</p> <p>2)I'm not looking for definitions how to take the color or how calculate the area, I already have it and in order to simplify the problem I didn't mention it. What I'm looking for is WHERE and HOW to add this child area </p> <p>Thank you very much</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload