单击页面加载后添加的跨度元素

Click on span elements that is added after page loads

我有一个div。单击一个词后,div 会出现一些跨度。 代码:

<div id="show-data">
  <span>Erprobung</span> 
  <span>Probe</span> 
  <span>Prüfung</span> 
  <span>Test</span>
</div>

我的问题:我也想点击新的 span-tags,但它对我不起作用。这是我的代码:

$('$data-show').on('mouseover','span',function(){
    alert("Test");
});  
<div id="show-data"></div>

这个问题的解决方案是什么?非常感谢。

使用 #show-data 代替 $data-showclick() event instead of mouseover() 事件。

$('#show-data').on('click','span',function(){
  alert($(this).text());
});
    
var count = 0;
$('button').on('click', function(){
  count = count+1;
  $('#show-data').append('<span>Test'+count+'</span>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="show-data">
    <span>Erprobung</span> 
    <span>Probe</span> 
    <span>Prüfung</span> 
    <span>Test</span>
    </div>
    <button>Add Span</button>