0

Possible Duplicate:
styling XML (not HTML) with javascript & css after rendering in browser

Is it possible to access the CSS-styled properties of an XML document being displayed in a browser?

The element is accessible using, say, .getElementsByTagName(). And the browser correctly applies the CSS styling. And the debug panel (Firebug in FF, Dev Tools in Chrome) report the styles. So the data is in there somewhere.

But all these return either null or undefined:

document.getElementsByTagName("pb")[1].style
document.getElementsByTagName("pb")[1].css
document.getElementsByTagName("pb")[1].getAttribute('style')
document.getElementsByTagName("pb")[1].getAttribute('css')

Does the DOM not expose the styling?

Update: The open question asks about changing the styling. This one asks only about accessing the styling.

If in fact, read-only access is all that's needed, use .getComputedStyle().

4
  • Yes, that does seem basically the same question. Has the answer changed in three years? Commented Jan 20, 2013 at 3:15
  • Have you tried document.getElementsByTagName("pb")[0].style? Using an index of 1 as in the question gets you the second element... Commented Jan 20, 2013 at 3:25
  • XML documents are definitely meant to be styled with CSS. Vendors describe how to do it. It works well. The debug tools work well on it. CSS now supports XML namespaces. Etc. Commented Jan 20, 2013 at 3:40
  • Safari, for example, adds a default style with id xml-viewer-style to the document, then breaks all the code in the page. You might want to check the document tree in console. You will be surprised. Commented Jan 20, 2013 at 4:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.