javascripthtmlsoft-hyphen

Find soft hyphens in HTML document


Let's look at following code:

$('#el').html('ex­am­ple');

Now, how can I get back that element's text with soft hyphens entities? Both of these:

$('#el').html();
$('#el').contents().get(0).nodeValue;

gives me "example" as return value, not "ex­am­ple"

jsFiddle link: http://jsfiddle.net/w7QKH/

Browser: FF7, not checked in other browsers.


Solution

  • Actually $('#el').html() gives you 'example' with soft hyphens. If you run $('#el').html().length it will return 9. So hyphens are in, but they are not displayed. And it is not equal 'ex­am­ple' , because this string is not escaped. If you want to compare to string you should use 'ex\u00ADam\u00ADple'- here I replaced ­ with its unicode value. http://jsfiddle.net/w7QKH/1/