I'm trying to remove all ­
entities (soft hyphens) from my element,
I've been trying to do this using jquery. When I fetch the text from the html element containing the entity I seem to get a string where the entity is "hidden" or can't be edited.
Do you have to do something in particular to actually get a string including the entities?
$( document ).ready(function(){
$("button").on("click", function(){
var html = $("div > span").html();
var newHtml = html.replace("­", "");
$("div > span").html(newHtml);
});
});
div{
max-width: 50px;
padding: 10px;
border: 1px solid #000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span>My text will be hyphe­ned</span>
</div>
<button>
Remove Hyphens
</button>
Here's our top five best apps to remove background from photo for iPhone and Android in 2022: YouCam Perfect: Best Free Background Remover. PhotoCut Remove Background PNG. Magic Eraser Background Editor.
They are FREE on remove.bg and significantly cheaper than regular images (¼ credit instead of 1 credit) when requested through the API.
Use regex:
var newHtml = html.replace(/\­/gi, "");
Note: You may also need to check for ­
, because browser treats it in numbers and not in human friendly chars too.
Explanation:
/(\­)/gi
1st Capturing group (\­)
\& matches the character & literally
shy; matches the characters shy; literally (case insensitive)
g modifier: global. All matches (don't return on first match)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Snippet
$( document ).ready(function(){
$("button").on("click", function(){
var html = $("div > span").html();
var newHtml = html.replace(/(\­||­)/gi, "");
$("div > span").html(newHtml);
});
});
div{
max-width: 50px;
padding: 10px;
border: 1px solid #000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span>My text will be hyphe­ned</span>
</div>
<button>
Remove Hyphens
</button>
Regex101: https://regex101.com/r/wD3oX7/1
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