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
  • 169,008
  • 28
  • 173
  • 236
Wizard
  • 10,985
  • 38
  • 91
  • 165

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.

trenthaynes
  • 1,668
  • 2
  • 16
  • 28