preventdefault

Vue.js: How to prevent browser from going to href link and instead only execute the @click method?

北城余情 提交于 2020-12-25 05:56:18
问题 So I have a link in my application like this: <a href="/threads/my-first-thread/" @click="openThread">My first thread</a> At the moment, when I click the link, the browsers follows the href link and also executes the "openThread" method. I want to keep the link in there so that it shows the user where a click is going to bring him to, but I don't want the browser to actually follow the link (I open a lightbox instead and change the url with pushState). I want it to only execute the given

Prevent href from opening link but still execute other bind events

天涯浪子 提交于 2020-04-07 21:59:12
问题 I want to prevent links from opening pages. So I have written this : $("a").click(function(e) { e.preventDefault() } which is great! But this blocks my other event : $(".toolbar a").click(function(e) { ...action... } Sure I can add my action to the first event with some test, but is there an elegant way to prevent only href event from executing? EDIT In fact it works, sorry. See @raina77ow fiddle working here: http://jsfiddle.net/HeFS6/ 回答1: Use return false instead. You can see the code

javascript preventDefault only on parent item

蹲街弑〆低调 提交于 2020-02-06 05:53:25
问题 I am creating a drop down nav in javascript. Any list items that have children i would like to prevent the default action and do something else. I have this working but when applied the default action is also applied to the child list items. Here is my HTML: <i id="mobnavtrig" class="fa fa-align-justify fa-2x"></i> <div class="mobilenav"> <li class="page_item page-item-2"><a href="/">Home</a></li> <li class="page_item page-item-10"><a href="?page_id=10">Who We Are</a></li> <li class="page

mouse event still fired on touch event even with preventDefault set

ε祈祈猫儿з 提交于 2020-01-24 22:35:27
问题 is there anything I misunderstood here? I often use code like the following in my site that I want to work either for desktop and iPad device: $("#someElement") .on( "mousemove", function(e) { alert ( "I am still here" ); // undesired code for ipad here } ) .on( "touchmove", function(e) { e.preventDefault(); // only desired code for ipad use here } ); I read in many places that the e.preventDefault should kill the mouse events attached. And that the touch events are elaborated in the first

jQuery preventDefault not prevent anchor's behaviour

痞子三分冷 提交于 2020-01-24 19:27:07
问题 I have a menu that filters through categories and hides or displays whatever category is clicked on. The filtering is working fine but for some reason I can't stop the anchor's default behaviour. The anchor has a '#' and every time it is clicked it takes you to the top of the page which is no good UX. I need it to stay where it is so that filtering happens without moving the user to the top of the page. Any help would be appreciated. Thanks, Here is my jquery: $(".portfolio-nav li:first-child

How to Prevent Bubbling For Form Submit

╄→尐↘猪︶ㄣ 提交于 2020-01-16 00:36:30
问题 I have form that calls the function GenerateWords when it is submitted and returns false. <form id="3Form" onsubmit="GenerateWords(this); return false;"> This is causing problems with Google Tag Manager implementation as it does not bubble up to the form submit listener. I understand event.preventDefault(); needs to be used and return false removed but don't know how to implement this. The current javascript I have is: function GenerateWords(F) { var strWords = F.words.value; if ... condition

Preventing touch from generating mouseOver and mouseMove events in Android browser

余生长醉 提交于 2020-01-13 10:30:15
问题 I am building a page that needs to work with touch and mouse interaction on PC, Mac, and mobile browsers. In the event handler methods for touchStart, touchMove, touchEnd, and touchCancel I am calling event.preventDefault to prevent mobile browsers from firing both touch and mouse events. This works great for mouseDown and mouseUp, which do not get fired when I touch the screen, but for some reason a short while (couple 100ms) after each touchStart is fired, the android browser still fires a

how to prevent focus event in IE when mousedown happens

99封情书 提交于 2020-01-10 03:01:07
问题 event.preventDefault(); return false; event.stopPropagation(); any of them can prevent focus event from happening when I trigger a mousedown event in Firefox and chrome, but it failed in IE.In fact,chrome has another problem. when mousedowning, :hover css is not working. ` <input type="text" id="name"> <div id="suggest"> <div>mark</div> <div>sam</div> <div>john</div> </div> $("#name").focus(suggest.show).blur(suggest.hide); ` what I expected is, when I click the sub div, such as "sam",and

jQuery preventDefault not working correctly on iOS 9

回眸只為那壹抹淺笑 提交于 2020-01-07 03:01:48
问题 I am using jQuery to fade in a search box in a fixed header like this... <script type="text/javascript"> jQuery(document).ready(function() { jQuery(".search_button").click(function() { event.preventDefault(); jQuery(".h_search").fadeIn("fast"); jQuery( "#search" ).focus(); }); }); </script> I am using preventDefault to stop the page jumping to the top when the link is clicked, it works correctly on an iPhone 4 with iOS 7 but on an iPhone 4s and iPad mini with 9 it doesnt work and the content

Jquery onclick prevent defaut behaviour

坚强是说给别人听的谎言 提交于 2020-01-06 02:51:09
问题 I'm writing a function : (function($) { $.fn.openBox = function(theId) { // do something }; })(jQuery); and several links calling my function like this : <a href="#" onclick="$(this).openBox('#theBoxId');">Open the box !</a> I know I can prevent default behaviour with return false : <a href="#" onclick="$(this).openBox('#theBoxId'); return false">Open the box !</a> But I want to put it in my jQuery function... I've tested with event.target but it doesn't seems to work... 回答1: You can return