Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3421568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:07:05+00:00 2026-05-18T06:07:05+00:00

I have somewhat of an odd situation, where I need to fix a bug

  • 0

I have somewhat of an odd situation, where I need to fix a bug in a website where, when a string is created (dynamically) it adds 5 spaces before the string and 5 spaces after the string. Obviously, the best thing to do would be to fix the back end code and get rid of those spaces… long story short, I can’t and I have to do it with javascript. I’m not quite sure how to do it, but this is what I was thinking

<!--Dynamically generated string including spaces added in backend-->
<span id="balance">     245.34     </span>

My idea was to do the following with javascript

function removespace()
{
  var oldString = document.getElementById('balance');
  var newString = (THIS IS WHERE I AM STUCK... I NEED TO REMOVE THE SPACES);
  document.getElementByID('balance').innerHTML = newString;
}

Does anyone have any suggestions?
Thanks!

ALSO FORGOT TO MENTION: I can’t use any javascript libraries like prototype or jquery.

Edit: I have this so far… but it doesn’t seem to be working:

<span id="balance">     $245.00     </span>

 <script>
 function removespace()
 {
   var oldString = document.getElementById('balance');
   var newString = oldString.trim ();
   document.getElementByID('balance').innerHTML = newString;
 }

 String.prototype.trim = function() {
 return this.replace(/^\s+|\s+$/g,"");
 }
 </script>

here is the solution I used… I finished it before I saw the other updates… but everyone was very helpful

function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
 }
 var oldString = document.getElementById('balance').innerHTML;
 var newString = trim(oldString);
 document.getElementById('balance').innerHTML = newString;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:07:05+00:00Added an answer on May 18, 2026 at 6:07 am

    Unfortunetly JavaScript does not have a trim() function. But you can roll your own:

    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
    }
    

    and then do:

    var newString = oldString.trim ();
    

    the above function is from this website (first result on google for “javascript trim”)

    edit (based on your update to your question and comments):

    change

    var oldString = document.getElementById('balance');
    

    to

    var oldString = document.getElementById('balance').innerHTML;
    

    and change

    document.getElementByID('balance').innerHTML = newString;
    

    to

    document.getElementById('balance').innerHTML = newString; // notice the lower case d
    

    and you have to call the removespace function at some point (but I’m sure you already do that) 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a somewhat odd situation. I understand the premise of the live() and
I have a question that may sound odd, but being somewhat of a newbie,
I need to extract a value from a hidden HTML field, have somewhat figured
I have somewhat interesting development situation. The client and deployment server are inside a
I have an odd case with Visual Studio 2003. For somewhat legitimate reasons, I
I have a somewhat odd problem. I have the following Backbone routes: routes: :
UPDATE: I have somewhat resolved the issue. Just in case if anyone runs in
Setting up a project structure; I am thinking is it better to have somewhat
I have a somewhat strange issue with visual studio. Almost every time I create
I have a somewhat simple Client/Server solution running over C# remoting (System.Runtime.Remoting). The MarshalByRef

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.