Calling jquery event handler from knockout compoenent

293
December 28, 2016, at 03:31 AM

I have a global event handler for all my buttons that looks like this:

$(".btn").mouseup(function () {
    $(this).blur();
});

Just something simple to make sure that buttons don't stay focused after the user clicks it.

However, this does not work for knockout-made components.

I don't think it would make sense to make a global event handler like the above only to make another one in my viewmode since that introduces redundant code. Is there any way to let the above event handler handle my knockout buttons as well as all the rest?

Answer 1

For anyone looking for the answer:

To make something like this work, one would have to delegate the handling of the event to a static container that knockout never touches such as document.

So to make a global event that will work for all, you would do something like:

$(document).on('mouseup', '.btn', function () {
    $(this).blur();
});

In my case.

READ ALSO
Need eventlistener for .click so that dynamically refreshed buttons work, but actions multiply

Need eventlistener for .click so that dynamically refreshed buttons work, but actions multiply

I have a page where one div:s content (not the whole page) refresh/reload/update if I make changes to the database

134
Is it possible to gather text from another website?

Is it possible to gather text from another website?

I want my iOS app to show some information from another website

24
Finding missing text or code in Dreamweaver

Finding missing text or code in Dreamweaver

Is it possible to find which pages in Dreamweaver are missing a certain snippet of code or text?

20
Image does not appear on site when uploaded to host server

Image does not appear on site when uploaded to host server

when viewing my website on my local drive, everything works and appears as intended, but when all of my files are uploaded to GoDaddy, one of my images does not show upI tried deleting and reuploading the file, but it simply won't appear on any browser...

7