I have the following table
<table>
<tr class="rows"><td>cell1</td><td>cell2</td></tr>
</table>
How can i set an alert message if i clicked on any of the column of <tr class="rows">
using jquery?
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!");
});
});
$(
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With