问题
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