user3724896
user3724896

Reputation: 139

Jquery repeating clicks when resizing

Jsfiddle

When I resize the window, the blue block is changing his size. If I click on blue block, I add symbol * to it. But if I click on the blue block, resize window, and again click on resized block, instead of one *, will add a lot of symbols *.

What's the problem? I need add one symbol *, after I resize the window.

function c_click() {
    $('.blue-block').click(function(){
        $('.blue-block').append('<div>*</div>')
    });
}


$(window).ready(function(){
    c_click();
})

$(window).resize(function(){
    c_click();
})

Upvotes: 0

Views: 128

Answers (1)

Dong
Dong

Reputation: 332

jQuery allows for multiple event handlers attached to one element. In this case, each time resize() is evoked, you register a click handler, which results in the multiple '*'

Upvotes: 2

Related Questions