javascript - Cancelling the anchor when clicking on a div inside the anchor -


i have anchor element in html:

<a class="info-tiles tiles-inverse has-footer" href="somepage.html?id=15">   <div class="tiles-heading">     <div class="pull-left">it department - hosting environment</div>   </div>   <div class="tiles-body">     <div class="nav-justified" style="font-size: small;">started: 19-05-2015 07:00</div>     <div class="btn btn-sm btn-default pull-right">ae</div>     <div class="btn btn-sm btn-default pull-right">pj</div>     <div class="btn btn-sm btn-default pull-right">sl</div>   </div>   <div class="tiles-footer">     <div class="progress">       <div class="progress-bar progress-bar-info" style="width: 20%"></div>     </div>   </div> </a> 

this code renders this:

example render

the behavior ok in general, clicking on anywhere in anchor should direct me page, i'd able click on lightgrey tiles [sl][pl][ae] , display context menu those. clean approach change behavior still can click anywhere navigate somepage.html, except if click on tiles, navigation should not happen, , instead fire javascript function (which display context menu)?

if use jquery, might want take approach:

$(".btn.btn-sm.pull-right").on("click", function(e) {     e.stoppropagation();      $(this).find(".context-menu").toggle();      e.preventdefault();     return false; }); 

then you'd need write

<div class="context-menu">     <ul>         <li>element</li>     </ul> </div> 

and style basic css.

edit: support older version of ie, might add after e.stoppropagation();

event.cancelbubble = true; 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -