jquery - How to disable anchor tag pressed -
how disable anchor tag when pressed jquery? tried e.preventdefault();
disabled anchor tags , not 1 pressed.
$(".header_menu .header_menu_res ul > .menu-item a, .content_res .header_menu_res ul > .menu-item a").live("click",function(e) { e.preventdefault(); if($(this).find(".adv_categories").length==1) { if($(this).find('.adv_categories').hasclass("importantrule")) { $(this).find('.adv_categories').removeclass("importantrule"); $(this).removeclass("importantrulebutton"); } else { if($(this).siblings(".menu-item").find(".sub-menu").hasclass("importantrule")) { $(this).siblings(".menu-item").find(".sub-menu").removeclass("importantrule"); } $(this).find('.adv_categories').addclass("importantrule"); $(this).addclass("importantrulebutton"); } } });
here html of li
<li id="menu-item-36" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-36"><a class="primary" href="http://www.test.co.uk/about-us/"><em class="icon-info"></em>about us</a> <ul class="adv_categories"><li></li></ul></li>
what happens page still goes about-us
. want disabled. when used e.preventdefault();
sub-menu
showed.
associated reply jsfiddle illustrates solution.
at high level, register handler click on anchor , when function associated handler invoked, passed event parameter. 1 can inquire event stop beingness propagated , result no default handling anchor navigation.
html
<a id="mya" href="http://www.ibm.com">go ibm</a>
javascript
$(function() { $("#mya").click(function(e){ alert("clicked"); e.preventdefault(); }); });
jquery
No comments:
Post a Comment