I'm trying to call the jQuery text()
function and run it through the trim()
function to remove all trailing and leading whitespace. Seems to work great in Firefox, however, does not work in IE7 (refuses to remove a space trailing at the end).
Any ideas?! Maybe a regex solution?
you most probably have forgotten about jquery chainning ...
try this
$('#selector').trim($('#selector').text())
don't be lazy with
$('#selector').text().trim();//this is wrong...
EDIT
or as @Laserson has simplified it even better, with $.trim($(selector).text());
So here's the gist of what was going on. I had some text in a span element and after that text there was a hyperlink/image the user could click to remove the text from the line it was on (see code below). However, I had put a
after the span element text (in the hyperlink's text) to put a bit of padding between the span text and the "delete" image. So even though I was accessing the element's text and trimming $.trim($(this).parent().text());
it would still include that space at the end! Once I removed this extra space, things worked fine. Still no idea why $.trim()
wouldn't take care of it though?!
<div>
<span>
<strong>SomeText</strong>
</span>
<a href="javascript:void(0);" onclick="removeMe();">
<img src="delete.png" width="15" height="15" border="0" name="imgRemove" />
</a>
</div>
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