Day/Night switch css solution

Yes but I don’t have any knowledge about how cookies are working. After searching in the forum, I tried to start by a php else/if statement I found here.

 <body class="<?php if(!cookie::exists('accepted')): ?>
                 day
                 <?php else(cookie::set('accepted', 'true', 1440*365)): ?>
                 night
                 <?php endif ?>
                 ">

But I don’t know how to activate it (by JS I suppose) by clicking <button class="daynight" onclick="daynight()">🔌</button>