Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since you're dynamically creating the table. You need to delegate. Since it looks like you are creating the table inside of the <code>#div_body</code> element, it would probably be the most efficient parent element to use. The element must exist in the dom when working with the element</p> <p>By using delegation the <code>.tbl_tr</code> click event will bubble up to the <code>#div_body</code> and that is where the event will be handled. By doing that it also reduces the amount of event handlers attached since by binding you would have attached one for every <code>.tbl_tr</code> element, now you just have one handling the events</p> <p>If using jQuery 1.7+ use <a href="http://api.jquery.com/on/" rel="nofollow">.on()</a></p> <pre><code>$('#div_body').on('click','.tbl_tr',function(){ alert($(this).attr("kode")); }); </code></pre> <p>or <a href="http://api.jquery.com/delegate/" rel="nofollow">.delegate()</a> if below 1.7</p> <pre><code>$('#div_body').delegate('.tbl_tr','click',function(){ alert($(this).attr("kode")); }); </code></pre> <p>Use above for dynamically created elements</p> <hr> <p>The two styles below are eventually the same thing</p> <pre><code>$(".tbl_tr").on("click", function(){ alert($(this).attr("kode")); //some function }); $(".tbl_tr").click(function() { alert($(this).attr("kode")); //some function }); </code></pre> <p>Use only when you know the element will be there when dom is loaded or you are attaching after the element has been added to the dom</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload