Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery variable increment ++ not working in script

I have this jQuery function that switches between different status messages (p elements) with ID's ranging from status_0 to status_5:

setTimeout(function() {
    var next_status;

    if (current_status < 5) {
        next_status = current_status++;
    } else {
        next_status = 0;
    }

    $(".status_visible").fadeOut("fast", function() {
        $("#status_"+next_status).fadeIn("fast");
    });

    //alert(next_status);

    change_status();
}, 10000);

My problem is that to start with, current_status definitely equals 0, but when it gets to my increment part, it comes out as 0 still! I tried this with a simple next_status = current_status + 1, which returned 01 instead of 1 (concatenated them), so I tried next_status = current_status++ and it returned 0 still.

Can anybody put me straight here please :)

like image 707
TheCarver Avatar asked Jul 25 '26 23:07

TheCarver


1 Answers

next_status = ++ current_status;
like image 195
Huang Tao Avatar answered Jul 28 '26 13:07

Huang Tao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!