stopPropagation not working as expected

stopPropagation not working as expected

Hello. I cannot get stopPropagation to stop the bubbling. I don't understand why; isn't this what it;s supposed to do? I am expecting that when I click on the "test" element that it will alert ('test clicked') and then stop ('prop failed') from being alerted.


  1. <div id="wrapper">
  2.     <div id="content">
  3.         <div id = "parent">
  4.             <div id="test" class="button">Top Button</div>
  5.         </div>
  6.     </div>
  7. </div>

  1. $('#parent').click(function () {
  2.     alert('prop failed');
  3. });


  4. $('#content').on('click', '.button', function (e) {
  5.     e.stopPropagation();
  6.     alert('test clicked');

  7. });