hide all checkboxes in table not working

被刻印的时光 ゝ 提交于 2019-12-11 08:34:42

问题


my jquery loops through all tables

I would like to hide all spans with the class="cbox" and all checkboxes within the current table but my code isnt working.

     var table_ids = new Array();
    $('.sizetable')
   .each(function(e){
    tableid = $(this).attr('id');


    //$msg = tableid;
    //alert($msg); This alerts the correct id 
    $( "#" + tableid + " .cbox").hide();
    $( "#" + tableid + " input:checkbox").hide();

     };

Here is the jsfiddle http://www.jsfiddle.net/tommyd/Br42j/


回答1:


Just use $('.sizetable .cbox, .sizetable input:checkbox').hide(). Selecting by ID is faster, but you're already selecting by class to get the ID, might as well just go from there and hide all .cbox and input:checkbox




回答2:


There is a syntax error, you are missing closing ')'. So change your code to:

var table_ids = new Array();
$('.sizetable').each(function(e){
    tableid = $(this).attr('id');
    //$msg = tableid;
    //alert($msg); This alerts the correct id 
    $( "#" + tableid + " .cbox").hide();
    $( "#" + tableid + " input:checkbox").hide();

});

Check the code below too(changed the selectors to make it little faster):

var table_ids = new Array();
$('.sizetable span.cbox, .sizetable input:checkbox').hide();

EDIT: Check this post at fiddle.net http://www.jsfiddle.net/Br42j/7/, I added the sizetable class to the table and added the missing ) And for optimized version check this: http://www.jsfiddle.net/Br42j/8/



来源:https://stackoverflow.com/questions/4703355/hide-all-checkboxes-in-table-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!