I'm developing a javascript function (used by a chrome extension) that would grab the largest text displayed (from font-size property) on a specific web-page.
It gets the content of the page specified through an ajax call and data that is returned by the call is transformed into the DomParser. Traversing the DOM, I get different Elements like:
[object HTMLDivElement]
[object HTMLUListElement]
[object HTMLLIElement]
[object HTMLDivElement]
Now I've written a function that gets the element style using getComputedStyle
. The logic I've in it is:
if(document.defaultView && document.defaultView.getComputedStyle)
{
strValue = document.defaultView.getComputedStyle(ele, null).getPropertyValue(cssProp);
}
//Where ele is the elements i got above (HTMLDIVElement e.g) and cssProp is 'font-size'
Function grabs around 460 different elements (test page) but font-size is always null. Can you please help setting this up?
window.getComputedStyle
returns [object CSSStyleDeclaration] object for all the traversed elements.
Document.getAttribute('attribute-name')
is working but that only gives the inline results and not the computed ones.
If there are other suggestion to achieve the same result, I'm open to them as well.
Thanks