title: Dynamic flag adding DOM elements with jquery
body: <p>I'm trying to add a button, when user click a <code>span</code> into a hierchical tree <code>ul</code> HTML elements. </p>
  
  <p>This is an example:</p>
  
  <pre><code>&lt;ul class="tree"&gt;
    &lt;li&gt;
      &lt;span class="li_cat"&gt;Food&lt;/span&gt;
      &lt;ul class="tree"&gt;
        &lt;li&gt;
          &lt;span class="li_cat"&gt;Fruit&lt;/span&gt;
          &lt;ul class="tree"&gt;
            &lt;li&gt;
              &lt;span class="li_cat"&gt;Red&lt;/span&gt;
              &lt;ul class="tree"&gt;
                &lt;li&gt;&lt;span class="li_cat"&gt;Cherry&lt;/span&gt;&lt;/li&gt;
              &lt;/ul&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;span class="li_cat"&gt;Yellow&lt;/span&gt;
              &lt;ul class="tree"&gt;
                &lt;li&gt;&lt;span class="li_cat"&gt;Banana&lt;/span&gt;&lt;/li&gt;
              &lt;/ul&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;span class="li_cat"&gt;Meat&lt;/span&gt;
          &lt;ul class="tree"&gt;
            &lt;li&gt;&lt;span class="li_cat"&gt;Beef&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;span class="li_cat"&gt;Pork&lt;/span&gt;&lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HoniG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HoniG.png" alt="enter image description here"></a></p>
  
  <p>And the jquery code is this:</p>
  
  <pre><code>$(document).on('click', '.li_cat', function(e){
    e.stopPropagation();
    $(this).html($(this).html()+" &lt;button class='btn btn-warning btn-xs'&gt;&lt;i class='glyphicon glyphicon-pencil'&gt;&lt;/i&gt;&lt;/button&gt;");
  });
  </code></pre>
  
  <p>I want to display the button once, but every time I do click on add a new one, how can I solve this problem?</p>