Jquery row css problem
Html Code:
<table>
<tr>
<td>test</td>
</tr>
</table>
Jquery Code:
$(document).ready(function(){
$('table tr:eq(开发者_如何学运维0)').after('<tr><td>bla</td></tr>').css({'color':'red'});
});
ı need after append add css
<tr><td>bla</td></tr> >>> color red
How to make ?
Try this:
$('<tr><td>bla</td></tr>').css({'color':'red'}).appendTo('table');
You are adding css properties to your initial <tr><td>test</td></tr>
, not the one you're creating.
If you want to modify the on you've just created, you need to remember it in some variable first:
var tr = $('<tr><td>bla</td></tr>');
$('table tr:eq(0)').after( tr );
tr.css( {color:"red"} );
eq is a function mate. You can't use it inside the xpath string
you should go like $('selectors').eq(index)
Also .css is chained to the first selector. so it makes the first one red not what you are appending
$('tr').eq(0).after('<tr class="red"><td>bla</td></tr>');
and then your css is:
.red {color:red;}
精彩评论