Shubh Sheth Shubh Sheth - 1 year ago 100
Javascript Question

know if a boolean changed its value

when I load up the page the console log prints true but when i click the button nothing happens. I think that the event listener might help but i'm not quite good at javascript please help

<button class="shuffle">shuffle</button>
<script src=""></script>
<script type="text/javascript">
var player = $("#audioPlayer")[0];
var length = $("#queue li").length;
var shuffle = true;

$(".shuffle").on('click', function() {
if (shuffle === true) {
shuffle = false;
shuffle = true;
if (shuffle === true) {
if (shuffle === false) {

Answer Source

Define a function that performs what you want to do. Then you can call it when the page loads, and also when the user clicks.

function do_player_stuff(p) {
    if (shuffle) {
    } else {
        console.log("Not shuffling");

$(".shuffle").on("click", function() {
    shuffle = !shuffle;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download