title: javascript: string.replace doesn't work
body: <p>i have a little problem with replacing a string in javascript/jquery. First of all the code:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;fieldset&gt;
      &lt;legend&gt;Contact persons&lt;/legend&gt;
      &lt;div id="cm_contactPersons"&gt;
          &lt;fieldset id="cm_%email%"&gt;
              &lt;legend&gt;&lt;span class="glyphicon glyphicon-circle-arrow-right"&gt;&lt;/span&gt; %email%&lt;/legend&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="cm_%email_inputFirstname" class="col-sm-2 control-label"&gt;Firstname&lt;/label&gt;
                  &lt;div class="col-sm-10"&gt;
                      &lt;input type="text" class="form-control" id="cm_%email%_inputFirstname" value="%firstname%" placeholder="" required&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="cm_%email%_inputLastname" class="col-sm-2 control-label"&gt;Lastname&lt;/label&gt;
                  &lt;div class="col-sm-10"&gt;
                      &lt;input type="text" class="form-control" id="cm_%email%_inputLastname" value="%lastname%" placeholder="i. e. Max" required&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="col-sm-2 control-label"&gt;Actions&lt;/label&gt;
                  &lt;div class="col-sm-10"&gt;
                      &lt;button type="button" class="btn btn-warning"&gt;Create new password&lt;/button&gt;
                      &lt;button type="button" class="btn btn-danger"&gt;Delete contact person&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/fieldset&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>$(document).ready(function() {
      $('#cm_customerList').btsListFilter('#cm_customerSearchInput');
      var editingArea = $('#cm_editingArea');
      var contactPersons = $('#cm_contactPersons');
      var contactPersonsTpl = contactPersons.html();
      var alertArea = $('#cm_alertArea');
  
      $('#cm_customerList &gt; a').each(function() {
          $(this).click(function(e) {
              e.preventDefault();
              $('#cm_customerList&gt;a.active').removeClass('active');
              $(this).addClass('active', 400);
              $('html').animate({
                  scrollTop: 0
              });
              alertArea.fadeOut(400, function() {
                  alertArea.empty();
              });
              $.ajax({
                  type: 'GET',
                  url: 'index.php?' + $(this).attr('data-ajaxUrl'),
                  success: function(data) {
                      res = $.parseJSON(data);
                      editingArea.fadeOut(400, function() {
                          $('#cm_inputName').val(res.name);
                          $('#cm_inputStreet').val(res.street);
                          $('#cm_inputPostalcode').val(res.postalcode);
                          $('#cm_inputCity').val(res.city);
                          $('#cm_inputCountry option[value="' + res.country + '"]').prop('selected', true);
                          $('#cm_inputCountry').select2({
                              width: '100%'
                          });
                          $('#cm_inputTutors option:selected').prop('selected', false);
                          $.each(res.tutors, function(key, tutor) {
                              $('#cm_inputTutors option[value="' + tutor.username + '"]').prop('selected', true);
                          });
                          $('#cm_inputTutors').select2({
                              width: '100%'
                          });
                          contactPersons.empty();
                          $.each(res.contactpeople, function(key, contactPerson) {
                              contactPersons.append(contactPersonsTpl.replace('%email%', contactPerson));
                          });
                          editingArea.fadeIn();
                      });
                  },
                  error: function(xhr, ajaxOptions, thrownError) {
                      //error handler
                  }
              });
          });
      });
  });
  </code></pre>
  
  <p>The part with the "<code>contactPersons.append(contactPersonsTpl.replace('%email%', contactPerson));</code>" The replace simply doesnt work. I tried all various types of debugging (logs, changing substr etc.). No chance. </p>
  
  <p>But if I write "<code>$('#cm_contactPersons').html().replace('%email%', 'test@blubb.at');</code>" in the Firefox console, it works. </p>
  
  <p>What am I doing wrong?</p>