Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/03/2015, 12:12
cybervandal
 
Fecha de Ingreso: noviembre-2012
Mensajes: 76
Antigüedad: 11 años, 6 meses
Puntos: 3
id dinamico no me funciona

Tengo este código para seleccionar/deseleccionar checkbox:
Código:
<script type="text/javascript">
$(document).ready(function(){

	$( ".table" ).on('click', function(e) {
		id = $(this).attr("id");
	});					   
	
	var active_class = 'active';
	$('#idTabla > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
		var th_checked = this.checked;//checkbox inside "TH" table header
		
		$(this).closest('table').find('tbody > tr').each(function(){
			var row = this;
			if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
			else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
		});
	});
	
	$('#idTabla).on('click', 'td input[type=checkbox]' , function(){
		var $row = $(this).closest('tr');
		if(this.checked) $row.addClass(active_class);
		else $row.removeClass(active_class);
	});	
		
 });
</script>
y quiero remplazar el #idTabla con el id obtenido arriba en id = $(this).attr("id");
Pero no hay manera de que funcione, he probado por ejemplo:

Código:
...
$('#'+ id + ' > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
...
y de varias formas más pero no consigo que funcione.
Alguien me puede ayudar?