CSS :last-child selector in javascript? -
i looking select last td
in each row , using css selector right .table td:last-child
doesnt work in ie there way can select through javascript (without framework) ie? apply css styles.
var rows = document.getelementbyid('tester').rows; for(var = 0, len = rows.length; < len; i++) { rows[ ].lastchild.style.background = 'orange'; }
example: http://jsfiddle.net/jsyyr/
edit: if you'll running in browsers, may safer this:
var rows = document.getelementbyid('tester').rows; for(var = 0, len = rows.length; < len; i++) { rows[ ].cells[ rows[ ].cells.length - 1 ].style.background = 'orange'; }
example: http://jsfiddle.net/jsyyr/2/
this because browsers insert text node if there's space between last </td>
, closing </tr>
. such, lastchild
wouldn't work.
Comments
Post a Comment