4

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.

jesper
  • 879
  • 8
  • 21

2 Answers2

6

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/

welldan97
  • 3,071
  • 2
  • 24
  • 28
1

$('#el').html().replace(/\u00AD/g, '­');

See http://jsfiddle.net/K9mUy/

Alohci
  • 78,296
  • 16
  • 112
  • 156