~個ごとに要素のスタイルを変更する

Ads

Result

jQuery

    $('li').each(function(index){
        //3つごとに設定
        if(Math.floor(index/3)%2==0){
        //classを付加
            $(this).css('color','blue');
        }else{
            $(this).css('color','red');
        };
        });

html

<ul>
<li>list01</li>
<li>list02</li>
   ・
   ・
   ・
<li>list14</li>
<li>list15</li>
<li>list16</li>
</ul>

via

How to target list items per two lists instead of even or odd – Stack Overflow


Warning: include(/home/youhei0828/kachibito.net/public_html/wp-content/themes/cocoon-master/my-php/jquery-other-snippets.php): Failed to open stream: No such file or directory in /home/youhei0828/kachibito.net/public_html/wp-content/themes/kachibito7_with_cocoon_child/functions-module/shortcode/add-post-myphp.php on line 7

Warning: include(): Failed opening '/home/youhei0828/kachibito.net/public_html/wp-content/themes/cocoon-master/my-php/jquery-other-snippets.php' for inclusion (include_path='.:/opt/php-8.1.29/data/pear') in /home/youhei0828/kachibito.net/public_html/wp-content/themes/kachibito7_with_cocoon_child/functions-module/shortcode/add-post-myphp.php on line 7