Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 1.47 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JQuery: didnt get button id on click
  2. <table id="tblList">
  3.             <thead>
  4.                 <tr><th>Country Name</th>
  5.                     <th>CityName</th></tr>
  6.             </thead>
  7.             <tbody></tbody>
  8.         </table>
  9.        
  10. $("#tblList tbody").bind('click', function() {
  11.     $(this).find("tr").bind('click', function() {
  12.         $(this).find("input").bind('click', function() {
  13.             console.log($(this).attr("id"));
  14.         });
  15.     });
  16. });
  17.        
  18. $('#tblList .gridButton').click(function() {
  19.     console.log($(this).attr("id"));
  20. });
  21.        
  22. $('#tblList').append(table);
  23.        
  24. $('#tblList tbody').append(table);
  25.        
  26. $('body').on('click', '#tblList .gridButton', function() {
  27.     console.log($(this).attr("id"));
  28. });
  29.        
  30. $('#tblList .gridButton').live('click', function() {
  31.     console.log($(this).attr("id"));
  32. });
  33.        
  34. $("#tblList input").bind('click', function() {
  35.     console.log($(this).attr("id"));
  36. });
  37.        
  38. $("#tblList input").live('click', function() {
  39.     console.log($(this).attr("id"));
  40. });
  41.        
  42. function addRow(country, city, rowCount) {
  43.     var table = "<tr><td>" + country+ "</td><td>"
  44.         + city + "</td></tr>"
  45.         + "<tr><td colspan='2'><div id='divGridRow'><input type='button' value='add Zip Code' id='btn"
  46.         + rowCount + "' class='gridButton'/></div></td></tr>";
  47.  
  48.     $('#tblList').append(table);
  49.  
  50.     $('#btn' + rowCount).click(function () {
  51.         console.log($(this).attr("id"));    
  52.     });
  53. }
  54.  
  55. addRow("country 1", "city 1", 1);
  56. addRow("country 2", "city 2", 2);