Find soft hyphens in an HTML document

Take a look at the following code:

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

Now, how can I return this element text with soft suffixes? Both of these:

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

gives me an "example" as the return value, not "ex & shy; am & shy; ple"

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

Browser: FF7 not marked in other browsers.

+4
source share
2 answers

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

+5
source

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

See http://jsfiddle.net/K9mUy/

+1
source

Source: https://habr.com/ru/post/1380922/


All Articles