$.each($("tr"), function(i, val) { var temp = $("tr:eq(" + i + ") td:eq(1)"); if (temp.html() == 'tak') { temp.css('color', 'red'); } } );
Jednak jak na jQuery wydaje się dość skomplikowany. Pytanie brzmi: co źle napisałem lub co pominąłem?
$.each($("tr"), function(i, val) { var temp = $("tr:eq(" + i + ") td:eq(1)"); if (temp.html() == 'tak') { temp.css('color', 'red'); } } );
$('tr > td:contains(tak)').each(function(){ $(this).css('color', 'red'); });
$('tr').find('td:contains(tak):eq(0)').each(function(){ $(this).css('background', 'red'); });
$('tr').each( function() { var name = $(this).find('td:eq(0)').html(); $(this).find('td:eq(1)').click( function() { update(name, $(this).html()); } ); } );
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <script type="text/javascript"> $().ready(function(){ $(".xx").click(function(){ alert($(this).prev('td').text()); }); }); </script> </head> <body> <table> </table> </body> </html>
$('tr').find('td:contains(tak)').each(function(){ $(this).css('background', 'red'); });
$('tr').find('td:eq(1)').click( function() { alert($(this).prev('td').html()); } );