javascript - I cannot figure out how to exculde links from preventdefault -
i want exclude links inside child-div preventdefault
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script> <script> $(document).ready(function(){ $("#parent").click(function(event){ event.preventdefault(); }); }); </script> </head> <body> <div id="parent"> <div id="child"><a href="mylink.html" alt="link">click me!</a></div> </div> </body>
is possible link in child div
working? have spent 3 hours looking answer right now, , can't seem figure out!
check target triggered event not anchor. if not not propagate event.
$(document).ready(function(){ $("#parent").click(function(event){ if(!$(event.target).is("a")){ event.preventdefault(); } }); });
Comments
Post a Comment