Nits February 2016

While resize browser window counter variable value should be incremented by 1 value

I am facing a problem whenever I resize the browser window by (CTRL+SHFT+M) or change the orientation of window. counter_ variable value increament by 4 or 7 instead of 1.

HTML:

<div id="my_element">
    <span id="text">0</span> window resize.
</div>

Script:

$(function () {
    var counter_ = 0;
    $(window).on('resize', function () {
        $('#text').text(++counter_);
    });
});

Output Should be:

0 window resize.

1 window resize.

2 window resize.

..

..

Answers


jcubic February 2016

Try:

$('#my_element').append('<span class="text">' + (counter_++) + '</span> window resize.');

As in this FIDDLE

Post Status

Asked in February 2016
Viewed 2,706 times
Voted 5
Answered 1 times

Search




Leave an answer