HTML Anchor tag redirect link after ajax request

Use event.preventDefault, then on success, use location.href = self.href $(“.selectAnchor, .menuAnchor”).click(function(event){ event.preventDefault(); console.log(event.target.nodeName); var self = this; $.ajax({ type: ‘POST’, url: ‘http://localsite/menuRedirect.php’, data: {id:0, module:’Module’,source:’Source’}, complete: function(data){ console.log(“DONE”); location.href = self.href; } }); }); Or make use of the context property to remove var self = this $(“.selectAnchor, .menuAnchor”).click(function(event){ event.preventDefault(); console.log(event.target.nodeName); $.ajax({ type: ‘POST’, context: … Read more

PreventDefault alternative for IE8

I use something like: (event.preventDefault) ? event.preventDefault() : event.returnValue = false; the event.returnValue property is the closest IE equivalent to preventDefault. Using return false; can sometimes also work, but it can lead to unexpected behavior sometimes when mixed with e.g. jQuery (jQuery also does stopPropagation…which is usually what you want, but…), so I prefer not … Read more

Can’t prevent `touchmove` from scrolling window on iOS

I recently ran into this same problem. You’ll need to pass { passive: false } when registering the touchmove event listener. e.g. document.addEventListener(‘touchmove’, function(e) { e.preventDefault(); }, { passive: false }); This is because document touch event listeners are now passive by default in Safari 11.1, which is bundled with iOS 11.3. This change is … Read more

What is the opposite of evt.preventDefault();

As per commented by @Prescott, the opposite of: evt.preventDefault(); Could be: Essentially equating to ‘do default’, since we’re no longer preventing it. Otherwise I’m inclined to point you to the answers provided by another comments and answers: How to unbind a listener that is calling event.preventDefault() (using jQuery)? How to reenable event.preventDefault? Note that the … Read more

React onClick and preventDefault() link refresh/redirect?

React events are actually Synthetic Events, not Native Events. As it is written here: Event delegation: React doesn’t actually attach event handlers to the nodes themselves. When React starts up, it starts listening for all events at the top level using a single event listener. When a component is mounted or unmounted, the event handlers … Read more

Bootstrap 3 – disable navbar collapse

After close examining, not 300k lines but there are around 3-4 CSS properties that you need to override: .navbar-collapse.collapse { display: block!important; } .navbar-nav>li, .navbar-nav { float: left !important; } .navbar-nav.navbar-right:last-child { margin-right: -15px !important; } .navbar-right { float: right!important; } And with this your menu won’t collapse. DEMO (jsfiddle) EXPLANATION The four CSS properties … Read more

When to use PreventDefault( ) vs Return false? [duplicate]

return false; return false; does 3 separate things when you call it: event.preventDefault() – It stops the browsers default behaviour. event.stopPropagation() – It prevents the event from propagating (or “bubbling up”) the DOM. Stops callback execution and returns immediately when called. Note that this behaviour differs from normal (non-jQuery) event handlers, in which, notably, return … Read more

How to preventDefault on anchor tags?

According to the docs for ngHref you should be able to leave off the href or do href=””. <input ng-model=”value” /><br /> <a id=”link-1″ href ng-click=”value = 1″>link 1</a> (link, don’t reload)<br /> <a id=”link-2″ href=”” ng-click=”value = 2″>link 2</a> (link, don’t reload)<br /> <a id=”link-4″ href=”” name=”xx” ng-click=”value = 4″>anchor</a> (link, don’t reload)<br /> … Read more