Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8764053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:56:06+00:00 2026-06-13T15:56:06+00:00

Overview When creating a knockout custom binding that contains a call to a knockout

  • 0

Overview

When creating a knockout custom binding that contains a call to a knockout default binding, my custom binding stops working after the first call.

To see the issue, in the JSFiddle example, change the selected item in the ddl once. Text changes as expected. Change it again, and nothing happens. Fail.

Details

I am seeing some odd behavior when extending the default knockout binding “html” with my own custom binding “htmlFade”. The behavior I am looking for is the same as the html binding, but with a JQuery fade animation to fade DOM elements in and out.

Code samples below. A full JSFiddle example can be see here.

The HTML looks like this:

<select data-bind="options: names, value: selectedName"></select>  
<data-bind="htmlFade : selectedName" class="main"></div>

The Json Data looks like this:

var viewModel = {
    names: ko.observableArray(['Bob', 'Jon']),
    selectedName: ko.observable('Bob')
};

The Custom Binding looks like this:

ko.bindingHandlers.htmlFade = {
    init: function(element, valueAccessor) {
        ko.bindingHandlers.html.init();
        $(element).hide();
    },
    update: function(element, valueAccessor) {
        $(element).fadeOut(700, function() {
           ko.bindingHandlers.html.update(element, valueAccessor);           
           $(element).fadeIn(700);
        });        
    }
};

I am intentionally deferring to the default html handler with the line “ko.bindingHandlers.html.update(element, valueAccessor)”, because my goal is to extend the behavior, not recreate.

The problem I am having is that the above code works the first time select list is changed. After that it fails.

I created another JSFiddle example where instead of extending the behavior, I recreated it by adding the following line “http://jsfiddle.net/jamshall/kYwEE/1/&#8221; (copied from the knockout source for the default html binding) in place of the above referenced html.update call. This seems to work fine.

My question, then, is why does my Custom Binding stop working after the first call when I include a call to a default binding from withing it? Or, to make it simple, why does JSFiddle1 not work but JSFiddle2 work?

Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:56:08+00:00Added an answer on June 13, 2026 at 3:56 pm

    You can think of the update function of a custom binding like a computed observable (Knockout does use computed observables to track dependencies when the bindings on an element are executed). So, in your custom binding you are not grabbing a dependency to the observable that you are bound against, because your code is being executed asynchronously.

    In your update, you would probably want to do something like:

    update: function(element, valueAccessor) {
        //just grab dependency
        ko.utils.unwrapObservable(valueAccessor());
    
        $(element).fadeOut(700, function() {
           ko.bindingHandlers.html.update(element, valueAccessor);           
           $(element).fadeIn(700);
        });        
    }
    

    So, we just access the value of the observable to grab a dependency. ko.utils.unwrapObservable just safely handles retrieving the value no matter if it is a non-observable or observable.

    Updated sample: http://jsfiddle.net/rniemeyer/6UtsP/10/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a fiddle to demonstrate my issue: http://jsfiddle.net/motocomdigital/QyhpX/5/ OVERVIEW I'm creating a tabbed
I've been creating a blog, which contains of 3 diffrent views. - Overview -
Overview: I am writting an application to dynamically load .dlls and call their methods.
Overview: I have an advancedDataGrid that I am using a GroupingCollection on and I
Overview I have an iOS project which contains 2 navigation controllers as shown in
I am creating a plugin and it cannot access $(this). A simple overview of
First a short overview of my code, i hope its understandable: I have a
I'm creating a overview of TopDesk. I've wanted to ask some of you what
For a web application I'm creating (in Umbraco, but don't think that really matters
Overview: I'm working on some windows service using Visual Basic 2010, which deployed on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.