title: Why an unexpected <br> being inserted by replace() function?
body: <p>I'm seeing some very unexpected behavior with the replace() javascript function that I'm using. Essentially, if the user inputs <em>[Hi there]</em> into a text form, I want to replace the brackets <strong>[</strong> and <strong>]</strong> with tags that will add margin to the text for e.g. <code>[Hi there]</code> to <code>&lt;div&gt;Hi there&lt;/div&gt;</code>. In addition to the desired tags, a <code>&lt;br&gt;</code> tag is also added after the closing div. </p>
  
  <p>Here is my code:</p>
  
  <p>javascript</p>
  
  <pre><code>$('.servicebody').each(function() {
    var string = $(this).html();
    $(this).html(string.replace(/\[/g, '&lt;div class="marginme"&gt;')); // to replace opening square bracket
  });
  
  $('.servicebody').each(function() {
    var string = $(this).html();
    $(this).html(string.replace(/\]/g, '&lt;/div&gt;')); // to replace closing square bracket
  });
  </code></pre>
  
  <p>css</p>
  
  <pre><code>.marginme {
    margin: 10px auto;
  }
  </code></pre>
  
  <p>Any thoughts on why a <code>&lt;br&gt;</code> tag is being inserted by this replace() function?</p>