问题描述:

Suppose a document like this:

<style type="text/css">

.my-bold {

font-weight: bold;

}

</style>

<p id="first">Paragraph with <span class="my-bold">bold text</span></p>

<p id="second">Another Paragraph with <span class="my-bold">bold text</span></p>

I'd like to extract the second paragraph with styles applied:

<p id="second">Another Paragraph with <span class="my-bold" style="font-weight: bold">bold text</span></p>

Is there an API for this? I tried Range.cloneContents()

var p = document.getElementById( "second")

var range = document.createRange()

range.selectNode( p)

var html = range.cloneContents()

But this gives me only the HTML without styles:

<p id="second">Another Paragraph with <span class="my-bold">bold text</span></p>

A WebKit-only solution would be sufficient.

相关阅读:
Top