2014-06-16 76 views
1

嗨,我無法觸發我的代碼的簡單事件委託,所選DIV內的DOM元素是動態創建的。無法觸發事件委託

<div class="holder" style="-moz-user-select: none;"> 
    <a class="jp-previous page1"> previous</a> 
    <a class="page">1</a> 
    <span class="jp-hidden">...</span> 
    <a class="page jp-current">2</a> 
    <a class="jp-next page1 jp-disabled">next </a> 
</div> 

以下是我的JS代碼,我正在就緒塊內執行。

jQuery("div[class=holder]").on('click',function() { 
     alert('i am here'); 
    }); 
+0

你的語法是錯誤的'jQuery的(文件)。在( 'click','div [class = holder]「,function(){..});' - 也使用類選擇器而不是屬性sele ctor所以'jQuery(document).on('click',「.holder」,function(){..});' –

+0

@ArunPJohny:已經嘗試過它不工作太 –

+0

然後嘗試使用類選擇器,如我所說更新的評論 –

回答

1

試試這個....

jQuery(document).on('click','div[class=holder]',function() { 
     alert('i am here'); 
    }); 

也可以使用

jQuery(document).on('click','.holder',function() { 
      alert('i am here'); 
     }); 
+0

'jQuery(「文檔」)'.....真的嗎? – Jai

1

嘗試,

jQuery(document).on('click',".holder",function() { 
相關問題