1

I am trying to get the html source of a website including all the styles of the elements set by the css. So basically the rendered html of the page, such that if an element is hidden it has style = display:none

When using the functions below style attributes added by the css are not included in the string.

document.getElementsByTagName('html')[0].innerHTML;

or

inDocument.documentElement.innerHTML;

Is there a way to include the css attributes?

Thanks, James

2
  • I'm actually passing the html string back to java so iframes aren't an option Commented Jun 7, 2012 at 5:02
  • Sorry, actually posted an answer and then checked this.. This may be of some help stackoverflow.com/questions/4781410/… Commented Jun 7, 2012 at 5:24

2 Answers 2

1

I don't think jQuery is necessary for fetching the HTML Source. Just use

document.documentElement.outerHTML

This will include the CSS attributes as well.

Sign up to request clarification or add additional context in comments.

2 Comments

Will it include computed styles also?
Sorry, actually posted an answer and then checked this.. This may be of some help stackoverflow.com/questions/4781410/…
1

This will help you jQuery CSS plugin that returns computed style of element to pseudo clone that element?

Also check the jQuery clone function mentioned here http://api.jquery.com/clone/

2 Comments

So I could run that as I parse the elements and add them to a string? Then return the string.
>>add them to a string Not sure. But you can add them to an object, because clone() returns a jQuery object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.