title: How do I get div to show when user enters restricted character in jQuery?
body: <p>Hello :) I have a form with an input that I have restricted the characters that can be used using jQuery. I would like for a div to display next to or under the input field if a restricted character is pressed.</p>
  <p>So far I have:</p>
  <pre><code>jQuery(document).ready(function($) {
    $('#15').keypress(function(e) {
      var regex = new RegExp(&quot;^[a-zA-Z0-9-_\s]+$&quot;);
      var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
      if (regex.test(str)) {
        return true;
      }
      e.preventDefault();
      $(codeBlock).appendTo($('#15'));
      return false;
    });
  });
  </code></pre>
  <p>With codeBlock being a variable containing HTML. I can see the HTML in the page source but it isn't actually displaying it and places it under &quot;Shadow Content&quot; which sounds cool but doesn't help me any. It is appending it in the right place, just not showing it.</p>
  <p>I've been working on this longer than I'd like to admit. Any help or guidance is greatly appreciated. Have a great day!</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const codeBlock = '&lt;div&gt;' +
    '&lt;h1&gt;I said only numbers and letters&lt;/h1&gt;' +
    '&lt;/div&gt;';
  
  jQuery(document).ready(function($) {
    $('#15').keypress(function(e) {
      var regex = new RegExp("^[a-zA-Z0-9-_\s]+$");
      var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
      if (regex.test(str)) {
        return true;
      }
      e.preventDefault();
      $(codeBlock).appendTo('#15');
      return false;
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;input name="input_15" id="15" type="text" value="" class="medium " placeholder="Only letters and numbers allowed"&gt;</code></pre>
  </div>
  </div>
  </p>