Select every other element of class using css3

后端 未结 3 634
夕颜
夕颜 2021-01-12 11:08

Given an ul with a structure like this:

  • ...
  • ...
3条回答
  •  悲哀的现实
    2021-01-12 11:32

    This cannot be done with plain CSS (in any way that I yet know of), however a plain-JavaScript solution is pretty simple:

    var​ lis = document.querySelectorAll('li.product');
    
    for (var i=0,len=lis.length;i

    JS Fiddle demo.

    jQuery could be used instead (as could, presumably, any other JavaScript library), but it's certainly not required.

提交回复
热议问题