this drives me nuts - Im trying to remove all white-spaces in a string, and nothing seems to work. what am i doing wrong?
This is what im trying with at the moment:
$(".unfoldedlabel a").text().replace(/ /g,'');
HTML:
<span class="unfoldedlabel" colspan="6"><a>Accessories/Service & Support</a></span>
You're not updating the text in HTML. After removing the spaces, the innerText in DOM need to be updated.
Use .text(function):
$(".unfoldedlabel a").text(function (index, oldText) {
return oldText.replace(/\s+/g, '');
});
$(".unfoldedlabel a").text(function(i, t) {
return t.replace(/\s+/g, '');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<span class="unfoldedlabel" colspan="6"><a>Accessories/Service & Support</a></span>
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