I have the following HTML:
<div> </span>
<span> </span>
How can I get an .innerHTML
(or .innerText
) including the original whitespace? I tried jQuery's .html()
and .text()
, but they return an empty string.
Keep in mind that HTML ignores continuous whitespace. So if you have more than 1, it won't show up. If the jQuery .html() method isn't working for you (maybe they trim inside), you could also just get at the same inner html directly
alert($('#div').get(0).innerHTML)
you need to use .contents() then get the nodeValue... something like this,
$('span').contents()[0].nodeValue
here's a fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With