0

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

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Ali Baig
  • 3,819
  • 4
  • 34
  • 47
  • What does this mean: `grab something like the highest text displayed (from font-size property)`? Are you trying to get the value of the element with the largest text shown on the screen? – Rory McCrossan Jan 08 '15 at 15:47
  • Hi @RoryMcCrossan Yeah!! Trying to fetch the largest text shown on a web-page. – Ali Baig Jan 08 '15 at 15:49
  • Does DOMParser detaches the css styles associated with the HTML Element? – Ali Baig Jan 08 '15 at 15:57

0 Answers0