title: Preventing event bubbling (for javascript onclick events)
body: <p>I am using javascript to interact with a CMS which provides a button for users to add things to their basket.
  However, I am using the javascript to try and prevent the customer from doing so unless they have made a selection from a drop-down menu elsewhere on the page.</p>
  
  <p>As there are many different buttons that could potentially get them to the basket (including the example below) and all of which have different methods for doing so, rather than write many lines of code to prevent each method and then re-enable that method when a selection is made I am trying to do a kind of 'catch-all' fix where I just cover any such buttons / links with another div so as to effectively 'mask' the button below it until they make a decision.</p>
  
  <p>I first tried to use absolute positioned divs to do this which works beautifully until the user does something like re-size a textbox on the page and then suddenly my absolutely positioned div is in the wrong place!!</p>
  
  <p>So I'm now using JQuery's .wrap() which solves this problem nicely.. BUT.. Now I can't use z-index to position the div above the required buttons as those buttons are within the mask not below it!</p>
  
  <p>I have done a lot of reading about event bubbling but I am not sure whether I've not found the right information yet, or maybe I understand it correctly or possibly that event bubbling is leading me down the wrong path all together as I can't seem to take those concepts and apply them to this scenario.</p>
  
  <p>so.....</p>
  
  <p>given the following HTML structure:</p>
  
  <pre><code>&lt;div class="btnMask"&gt;
      &lt;div class="button"&gt;
          &lt;a onclick="pageSubmit();return false;" href="#" id="addToBasket"&gt;
              &lt;span&gt;Add to Basket&lt;/span&gt;
          &lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <ul>
  <li>where the div with class="btnMask" is added by my javascript.</li>
  </ul>
  
  <p>Plus the following JQuery:</p>
  
  <pre><code>$('.btnMask').click(function() {
      // prevent default actions and alert the customer to select something;
  });
  </code></pre>
  
  <p>How do I go about stopping the  tag firing when clicking the .btnMask div?
  and (in case the answer to that does not make the answer to my other question obvious...)
  How would I switch that on and off ? (I have a function that checks the drop-down onchange and sets the z-index to 99 / -99 so I would want to change this to incorporate this new method.)</p>
  
  <p>Thank you in advance for your help.</p>
  
  <p><strong>&lt;&lt; EDIT >></strong></p>
  
  <p>Using the initial answers to this I managed to solve the problems for links that take you away from the page using a regular href.</p>
  
  <p>So I have now fixed the links where the HTML is like the following:</p>
  
  <pre><code>&lt;div class="btnMask"&gt;
      &lt;div class="button"&gt;
          &lt;a id="nextPage" href="/link/toanotherpage.asp?id=667868465726122926234"&gt;
              &lt;span&gt;Click to go to Page 2&lt;/span&gt;
          &lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>However, like I said there are many methods being used to take people away from the page and and <strong>e.preventDefault();</strong> and <strong>e.stopPropagation();</strong> don't work for my original example (presumably because they use an onclick rather than a href ?).</p>
  
  <p>Is there a way to do the same thing as <strong>e.preventDefault();</strong> and <strong>e.stopPropagation();</strong> are doing on my .btnMask div but will also deal with contained links that are being trigged by an onclick?</p>
  
  <p>thanks</p>
  
  <p><strong>&lt;&lt; EDIT >></strong></p>
  
  <p>Updated the question title to reflect the exact issue rather than just event bubbling on regular links.</p>