Skip to content Skip to sidebar Skip to footer

Jquery For Getting Click Event On A Table Row

I have the following table
cell1cell2
How can i set an alert message if i

Solution 1:

You can use delegate for better performance which will attach click event to root container of rows i.e table

$(document).ready(function(){
    $("tableSelector").delegate("tr.rows", "click", function(){
        alert("Click!");
    });
});

Solution 2:

$(
  function(){
      $(".rows").click(
        function(e){
            alert("Clicked on row");
            alert(e.target.innerHTML);
        }
      )
  }
)

Example

Better solution

$(document).on("click","tr.rows td", function(e){
    alert(e.target.innerHTML);
});

Solution 3:

$(document).ready(function(){
    $("tr.rows").click(function(){
        alert("Click!");
    });
});

Solution 4:

$(".rows").click(function (){ 
   alert('click');
});

Post a Comment for "Jquery For Getting Click Event On A Table Row"