title: Trim white space before text in javascript
body: <p>Can't find the answer, I tried with what I found on this website and elsewhere but it never works. </p>
  
  <p>Goal : to trim white spaces before and after a word giving in the field DIV.</p>
  
  <p>Problem : everything works fine as long there is NO white space before a word ! There can already be text in the DIV of it can be an empty DIV where text can be inserted.</p>
  
  <p>I tried in the javascript in the DIV like <strong>trim(this)</strong> but that doesn't work. Even inthe script itself I tried  <strong>$.trim(editableObj.innerHTML)</strong> , nor <strong>editableObj.innerHTML.trim()</strong></p>
  
  <p>Nothing works ! </p>
  
  <p>JS </p>
  
  <pre><code>&lt;script&gt;
  function showEdit(editableObj) {
    $(editableObj).css("background", "#FFF");
  }
  
  function saveToDatabase(editableObj, column, linkmainid, nav, linkid) {
    $(editableObj).css("background", "#FFF url(loaderIcon.gif) no-repeat right");
    $.ajax({
      url: 'save'+nav+'.php',
      type: "POST",
      data: 'linkcat=' + column + '&amp;linktitle=' + editableObj.innerHTML + '&amp;linkmainid=' + linkmainid + '&amp;action=' + nav + '&amp;linkid=' + linkid,
      success: function(data) {
        $(editableObj).css("background", "#FDFDFD");
  
        window.location="/website/cms/menu.php";
      }
    });
  }
  </code></pre>
  
  <p></p>
  
  <p>HTML </p>
  
  <pre><code>&lt;div class="navnew" contenteditable="true" onBlur="saveToDatabase(this,'1','999999','navnew','111')" onClick="showEdit(this);"&gt;&lt;/div&gt;
  </code></pre>