CsQuery icon indicating copy to clipboard operation
CsQuery copied to clipboard

Text() vs. InnerText vs. jQuery difference

Open keleshev opened this issue 10 years ago • 2 comments

I'm trying to get inner text of a node, however .InnerText property seems to misbehave:

> CQ.Create("<hai>foo &amp; bar &nbsp; baz<br>qux</hai>").["hai"].[0].InnerText;;
"foo &amp; bar &nbsp; bazqux"

Compare to jQuery:

> $("<hai>foo &amp; bar &nbsp; baz<br>qux</hai>")[0].innerText
"foo & bar   baz\nqux"

At the same time Text() seems to work closer to jQuery:

> CQ.Create("<hai>foo &amp; bar &nbsp; baz<br>qux</hai>").["hai"].Text();;    
"foo & bar   bazqux"

Do you have a suggestion on how can I want to achieve behaviour similar to jQuery?

keleshev avatar Jul 02 '15 15:07 keleshev

Write CsQuery.Config.OutputFormatter = OutputFormatters.HtmlEncodingNone; before any CQ use.

asv7c2 avatar Jul 05 '15 10:07 asv7c2

@alexander1986 thanks, that makes output of .InnerText similar to .Text(). Although I wish I could get the exact behavior of jQuery.

keleshev avatar Jul 07 '15 08:07 keleshev