CSS Selectors - Selecting a specific child element

后端 未结 2 1306
死守一世寂寞
死守一世寂寞 2021-01-14 14:16

Here is my code snippet:

2条回答
  •  失恋的感觉
    2021-01-14 14:38

    If you have the ability to change the output of the shopping cart, you could add a class to the

tag, e.g. , , etc.

If you can't change your back-end, then it's a choice of front-end tech. The most cross-browser method is to use jQuery to apply the row classes. The other alternative, CSS3, isn't supported by any current IE; given that this is a shopping cart, you're probably interested in the widest level of browser support.

Something like:

$('#shopping-cart-totals-table tr').each(function(n){
    $(this).addClass('row'+n);
});

Alternatively, if you're only interested in the third item, use jQuery in the same way as CSS3:

$('#shopping-cart-totals-table tr:nth-child(2) .price').addClass('highlightClass');

提交回复
热议问题