title: jQuery .text() method returns turns into NaN in other function
body: <p>I'm trying to modify prestashop mobile navigation and 've got some difficulties 
  trying to append sub categories lists with new elements containing main category title. The title gets written as NaN.<br><br> <strong>Code:</strong></p>
  
  <pre><code>$('#maincategories &gt; li').children('a').each(function() {
  
          //here i remove original navigation icons so they wont get into title String.
          $(this).children('span').remove();
          var str = $(this).text().toString().replace(" ","");
  
          var generateSubmenuTrigger = function(action) {
              if (action == 'show') {
                  var triggerClass = 'showSubnav',
                  var parentTitle = "";
              } else if (action == 'hide') {
                  var triggerClass = 'hideSubnav';
                  var parentTitle = str;
              };
              return '&lt;a class="msubnav '+ class +'"&gt;'+
                         +parentTitle+
                     '&lt;/a&gt;';
          };
  
          $(this).parent('li').append(generateSubmenuTrigger('show'));
          $(this).parent('li').children('div').children('ul').append(generateSubmenuTrigger('hide'))
      });
  </code></pre>
  
  <p>I've been checking <code>parentTitle</code> string using console.log and it all was good until i push it inside my <code>generateSubmenuTrigger</code> function. It would be really nice if someone could explain why it becomes into NaN and how to fix it.</p>