title: Trying to truncate a string and replace with ... in JQuery
body: <p><strong>EDIT 2:</strong></p>
  
  <p><strong>I have just realised that my HTML is only displaying the artist &amp; song, not the album which is why when I had</strong> </p>
  
  <pre><code>alert(album);
  </code></pre>
  
  <p><strong>in there I was getting unexpected results. The jQuery trim is now working as expected.
  Blush
  Thank you for your answers which I will keep for other scripts.</strong></p>
  
  <p>I'm using JQuery to grab the last 10 songs played from a lastfm user and display them.</p>
  
  <p>I would like to truncate the album names down to x characters and replace with ...</p>
  
  <p>The string is:</p>
  
  <pre><code>album = item.album['#text'];
  </code></pre>
  
  <p>and it is displayed here:</p>
  
  <pre><code>$current.find('[class=lfm_album]').append(album);
  </code></pre>
  
  <p>I have tried using:</p>
  
  <pre><code>var shortText = jQuery.trim(album).substring(0, 10)
      .split(" ").slice(0, -1).join(" ") + "...";
  </code></pre>
  
  <p>but it just displays the full album string and no amount of fiddling or javascript seems to work.</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I have just tried </p>
  
  <pre><code>album = item.album['#text'];
  alert(album);
  </code></pre>
  
  <p>to see what it thinks is there and I get some very results that don't match any of the other strings produced by the script so really am stuck now!</p>
  
  <p>The full script is as follows:</p>
  
  <pre><code>/*---------------
   * jQuery Last.Fm Plugin by Engage Interactive
   * Examples and documentation at: http://labs.engageinteractive.co.uk/lastfm/
   * Copyright (c) 2009 Engage Interactive
   * Version: 1.0 (10-JUN-2009)
   * Dual licensed under the MIT and GPL licenses:
   * http://www.opensource.org/licenses/mit-license.php
   * http://www.gnu.org/licenses/gpl.html
   * Requires: jQuery v1.3 or later
  ---------------*/
  
  (function($){
      $.fn.lastFM = function(options) {
  
          var defaults = {
              number: 5,
              username: 'xxxxxxx',
              apikey: 'xxxxxxxx',
              artSize: 'medium',
              noart: 'images/noartwork.gif',
              onComplete: function(){}
          },
          settings = $.extend({}, defaults, options);
  
          var lastUrl = 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&amp;user='+settings.username+'&amp;api_key='+settings.apikey+'&amp;limit='+settings.number+'&amp;format=json&amp;callback=?';
          var $this = $(this);
  
          var container = $this.html();
  
          $this.children(':first').remove();
  
          if(settings.artSize == 'small'){imgSize = 0}
          if(settings.artSize == 'medium'){imgSize = 1}
          if(settings.artSize == 'large'){imgSize = 2}
  
          this.each(function() {
  
              $.getJSON(lastUrl, function(data){ 
                  $.each(data.recenttracks.track, function(i, item){
  
                      if(item.image[1]['#text'] == ''){
                          art = settings.noart;
                      }else{
                          art = stripslashes(item.image[imgSize]['#text']);
                      }
  
                      url = stripslashes(item.url);
                      song = item.name;
                      artist = item.artist['#text'];
                      album = item.album['#text'];
  // this is the part where I try to truncate "album"
  var shortText = $.trim(album).substring(0, 10)
      .split(" ").slice(0, -1).join(" ") + "...";
  
  
  
  
                      $this.append(container);
  
                      var $current = $this.children(':eq('+i+')');
  
                      $current.find('[class=lfm_song]').append(song);
                      $current.find('[class=lfm_artist]').append(artist);
                      //$current.find('[class=lfm_album]').append(album);
                      $current.find('[class=lfm_album]').append(shortText);
                      $current.find('[class=lfm_art]').append("&lt;img src='"+art+"' alt='Artwork for "+album+"'/&gt;");
                      $current.find('a').attr('href', url).attr('title', 'Listen to '+song+' on Last.FM').attr('target', '_blank');
  
                      //callback
                      if(i==(settings.number-1)){
                          settings.onComplete.call(this);
                      }
  
                  });
              });
          });
      };
  
      //Clean up the URL's
      function stripslashes( str ) {   
          return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
      }
  })(jQuery);
  </code></pre>
  
  <p>thanks for your help.</p>