我想点击一个特定的span元素时触发一个click事件。跨度元素实际上是按钮,其是在桌子上:Jquery点击没有选择.class DOM元素
以下工作:
$("th > span").click(function() {
alert('hi');
});
下不起作用:
$("th.sorting > span").click(function() {
alert('hi');
});
类从个元素的变化排序sort_asc或sorting_desc,我想触发一个特定的事件取决于哪种类型的按钮被点击。
UPDATE:
有趣的是,当我观看源I看到只有以下:
<th><span class = 'btn' style = 'width:90%'>Image<span id='i'></span></span></th>
...但是,当I '检查元素' 通过萤火我看到:
<th class="sorting" role="columnheader" tabindex="0" aria-controls="dispensers" rowspan="1" colspan="1" style="width: 187px; " aria-label="Image: activate to sort column ascending"><span class="btn" style="width:90%">Image<span id="i"></span></span></th>
我怀疑这不是我的问题的根源,虽然..因为我假设jquery知道后面的元素代码。
(该jQuery插件 '数据表' 是负责更新的代码)
UPDATE:
最终代码:
$('th').on('click', '.sorting > span', function() {
$("span#i").html('');
jQuery("span#i", this).html(' <i class=\"icon-chevron-up\"></i>');
});
$('th').on('click', '.sorting_asc > span', function() {
$("span#i").html('');
jQuery("span#i", this).html(' <i class=\"icon-chevron-down\"></i>');
});
$('th').on('click', '.sorting_desc > span', function() {
$("span#i").html('');
jQuery("span#i", this).html(' <i class=\"icon-chevron-up\"></i>');
});
外观:
小心共享html以及? – 2012-04-25 06:15:04
请发布您的HTML – 2012-04-25 06:15:45
它正在JSFiddle工作: http://jsfiddle.net/ZPCeK/ – Chinmaya003 2012-04-25 06:32:02