Run jquery on each table
Below I hav开发者_运维百科e some jQuery that runs through each table with the classname = sizetable
I would like to execute this:
$("#frontshade :radio").click(function() {});
But I'm not sure how to replace the #frontshade
with the id from the array
var table_ids = new Array();
$('.sizetable')
.each(function(e){
table_ids[] = $(this).attr('id');
// JQUERY TO EXECUTE ON EACH TABLE
$("#frontshade :radio").click(function() {};
//
});
You can write $(this).find('input:radio')
.
The .find()
method finds all descendants that match a selector.
Note that input:radio
is faster than :radio
.
As the documentation states,
$(':radio')
is equivalent to$('[type=radio]')
. As with other pseudo-class selectors (those that begin with a ":") it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector ("*") is implied. In other words, the bare$(':radio')
is equivalent to$('*:radio')
, so$('input:radio')
should be used instead.
jQuery's selectors are simple javascript Strings. So you could easily append other string to it:
$( "#" + $(this).attr('id') + " :radio").click(function() {};
That'll do the work ;)
精彩评论