Manipulation of the generated data Jquery

The question was asked: 49 years 9 months ago   views: 13
0

There is the example function:

$(document).ready(function () { var v1 = 0; var v2 = 0; $('#add').bind('click', function () { $('#list').append('<button id="'+v1+'" class="c1">'+tp+'</button>'); $('#'+(v1-1)).removeClass('c1'); v1++; v2++; }); $('#list-button').bind('click', function () { $('#'+(v2)).removeClass('c1'); $(this).attr('class', 'c1'); v2 = $(this).attr('id'); }); }); <span id="add">+</span> <span id="list"></span>

That is, it is possible to create a feature to switch between the list of created elements. But there is a problem with the second event: $('#list-button').bind('click' ... It just simply does not respond.

Asked: 01-01-1970 в 03:00:00

Answers   1

0

neverojatno worn out topic! use delegation:

$('#list').on('click', 'button', function () { ... });
  • .on()
Answered: 30-01-2013 в 19:49:59
Thanks, didn't know. - 30-01-2013 в 19:58:26