1
$('.spinner').on('click', '.btn:first-of-type', function() {
  var $input = $(this).closest('.numeric-btn').find('.spinner input');
  $input.val( parseInt($input.val(), 10) + 1).keyup();
});

When I replace div where is .spinner class with

$('.side-form > div.cart-form').replaceWith(cart_form);

Then click event does not work. What can be the problem ?

mplungjan
  • 155,085
  • 27
  • 166
  • 222
Wizard
  • 10,467
  • 37
  • 86
  • 159

1 Answers1

1

You need to bind the delegate to something higher in the DOM.

You could use $(document), but I would target the next parent up from where you are doing your DOM manipulation. As an example:

<div id='container-parent'>
    <div class='spinner'>
        <div class='btn btn-default'>
        </div>
    </div>
</div>

Then you could bind to 'container-parent':

$('#container-parent').on('click', '.btn:first-of-type', function(){...}

That should allow the delegate to stay remain intact.

whipdancer
  • 1,628
  • 2
  • 15
  • 27