Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  181] [ 4]  / answers: 1 / hits: 12392  / 11 Years ago, tue, february 11, 2014, 12:00:00

I'm trying to raise a click event whenever a user clicks on any td element inside the tbody.This is what I have so far but it's not raising the event, any ideas why?



<head runat=server>
<script src=Scripts/jquery-1.4.1.js type=text/javascript></script>
<script type=text/javascript>
$(#skuOptionsBody td).click(function () {
alert('clicked!');
});
</script>
</head>
<body>
<form id=form1 runat=server>
<table id=options border=1>
<thead>
<tr>
<td>
SWEET OPTION
</td>
<td>
DRINK OPTION
</td>
</tr>
</thead>
<tbody id=skuOptionsBody>
<tr>
<td style=text-align: center>
SO1
</td>
<td style=text-align: center>
DO1
</td>
</tr>
</tbody>
</table>
</form>
</body>


UPDATE:



Sorry I forgot to mention that I dynamically add rows to the table using jQuery and as I'm adding new rows I need them to be bound to this click event.How can this be done?


More From » jquery

 Answers
0

try this inside $(document).ready(function(){});



$(#skuOptionsBody td).bind('click', function () {
alert('clicked!');
});


OR for jquery > 1.7 you can make use of .on()



$(#skuOptionsBody).on('click', 'td', function () {
alert('clicked!');
});

[#47847] Monday, February 10, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyi

Total Points: 121
Total Questions: 100
Total Answers: 109

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;