Reputation: 15
I am working on a single page application and there are anchor tags in one of my page. while clicking on any anchor tag, i wrote my logic to execute.It is of the form,
$( "a" ).on( "click", function( e ) {
// My LOGIC CODE Here to change Window's Location.
});
It is getting executed fine for all my links which are of type (Ex: a href="/page1" ) except for one anchor tag which is using knockout binding.This anchor tag is of form ( a href="/page1" data-bind="click:myFunction" )
My problem is by clicking that anchor tag MyFunction() is called first and then it is executing the event my event handler and thus is not working properly.
Instead i want to execute my event handler first and then the function(Knockout's Click Binding).
Please provide a solution. THANKS IN ADVANCE .
Upvotes: 0
Views: 1358
Reputation: 3
Alternatively you may return true on your data-binding like this:
<a href="page1" data-bind="click: function () { myFunction(); return true;}">
Upvotes: 0
Reputation: 338218
Use the source, Luke. ;)
In the function that creates event handlers (like for the click
binding), there is this part:
if (handlerReturnValue !== true) {
// Normally we want to prevent default action.
// Developer can override this be explicitly returning true.
if (event.preventDefault)
event.preventDefault();
else
event.returnValue = false;
}
Just return true
from your myFunction
.
Upvotes: 0