title: JQuery window.resize is constantly prepending my HTML more than once
body: <p>I'm trying to make it so my jQuery doesn't prepend my HTML constantly as I resize my window and instead only prepend once.</p>
  
  <pre><code>$(window).on('resize', function(){
      if ($(window).width() &lt;= 1024) {
          $("header &gt; .content-max &gt; .row").prepend( '&lt;a href="#" class="logout"&gt;&lt;svg class="pulse" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 22.3 22.3" style="enable-background:new 0 0 22.3 22.3;" xml:space="preserve"&gt;&lt;g&gt;&lt;g&gt;&lt;path class="st0" d="M11.2,0C5,0,0,5,0,11.2c0,6.2,5,11.2,11.2,11.2c6.2,0,11.2-5,11.2-11.2C22.3,5,17.3,0,11.2,0z M17.6,17.6 c-1.7,1.7-4,2.7-6.5,2.7c-2.4,0-4.7-1-6.5-2.7C3,15.9,2,13.6,2,11.2c0-2.4,1-4.7,2.7-6.5S8.7,2,11.2,2c2.4,0,4.7,1,6.5,2.7 c1.7,1.7,2.7,4,2.7,6.5C20.3,13.6,19.4,15.9,17.6,17.6z"/&gt;&lt;path class="st0" d="M11.2,4.3c-0.6,0-1,0.4-1,1l0,11.8c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1l0-11.8C12.2,4.7,11.7,4.3,11.2,4.3z"/&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/a&gt;' );
          $("header &gt; .content-max &gt; .row").prepend( '&lt;a href="#" class="mobile-nav"&gt;&lt;span class="icon-bar"&gt;&lt;/span&gt;&lt;span class="icon-bar"&gt;&lt;/span&gt;&lt;/a&gt;' );
          $(".mobile-nav").click(function() {
              $(this).toggleClass("pushed");
              $("#main-nav").slideToggle(300);
          });
          $("body").prepend('&lt;a href="#" class="top"&gt;Top&lt;/a&gt;');
      }
  });
  </code></pre>
  
  <p>I get a strange effect where the SVG is added constantly as the window is resized. At the moment I've only managed to get this working properly on page load but am trying to make it behave like a media query.</p>
  
  <p>See example result:</p>
  
  <p><a href="https://i.stack.imgur.com/rpBT7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rpBT7.png" alt="enter image description here"></a></p>
  
  <p>EDIT: I've just noticed that this also breaks the window.load of it. :(</p>
  
  <p>Update: Rough JSFIDDLE here <a href="https://jsfiddle.net/t1xyyqfn/" rel="nofollow noreferrer">https://jsfiddle.net/t1xyyqfn/</a></p>