Reputation: 670
I am trying attribute a event to cells of differents columns of my bootstrap table.
The problem is: Although I have set a class to each column, the events attributed to this classes are not fired. I still tried set a class to each div added in cells, but its event also wasn't fired.
So, how can I get a td event using bootstrab table?
Upvotes: 2
Views: 7417
Reputation: 723
try This
$("#boottable").on('all.bs.table', function (e, name, args) {
console.log(name, args);
});
Upvotes: 0
Reputation: 3330
Here is the complete code for td click event for bootstap table
$(document).ready(function(){
$('table td').click(function(){
alert($(this).html());
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<p>Click on the td below</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Upvotes: 1
Reputation: 3411
Until you are showing us some code, you can try this,
$('body').on('click', '#tableID tr td', function(){
//whenever any td is clicked, this function will get called
});
you can change 'click'
with whatever event name you want to bind your td with.
I am delegating the event to body, because if you dynamically add your table elements to your html, direct binding to those events will not fire/work.
Upvotes: 1