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

  • Home
  • SEARCH
  • 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 8902521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:38:04+00:00 2026-06-15T01:38:04+00:00

It seems knockout destroys bindings on detached elements. So if I apply a binding

  • 0

It seems knockout destroys bindings on detached elements. So if I apply a binding and detach that element, not only will that binding not be computed while the element is detached but it will still be broken after the element is re-inserted back into the document.

So something like:

ko.applyBindings(items, $list[0]);

items.push('one');

$list.detach();

items.push('two');

$container.append($list);

items.push('three');

Here’s a fiddle: http://jsfiddle.net/nicholasstephan/KejYc/2/

The binding in $list should read one, two three, but instead every update after the detach is not computed.

What should I be doing here to make this work?

  • 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-15T01:38:05+00:00Added an answer on June 15, 2026 at 1:38 am

    Applying the bindings at the end makes your fiddle work. But I don’t imagine that’s what you are shooting for:

    var $container = $("#container");
    var $list = $('#list');
    var items = ko.observableArray([]);
    
    items.push('one');
    $list.detach();
    items.push('two');
    $container.append($list);
    items.push('three');
    ko.applyBindings(items, $list[0]);
    

    This SO thread suggests you just re-apply bindings after each detach or simply hide the elements instead of detaching them. There are also several comments suggesting that the approach be rethought in this case, which seems to be the best answer.

    Perhaps you could provide the desired behavior rather than a contrived example? That would probably go a long ways to suggesting alternative models. Assuming your goal is to create draggable elements (Off the cuff, it’s the only really likely scenario where I’d need to detach/re-insert elements), you could take an approach like this:

    1. drag initiated
    2. drag a copy of the element (leave original in doc)
    3. drag stopped
    4. copy any necessary data from original to copy
    5. insert the copied element at the new/valid location
    6. delete the old element
    7. call ko.applyBindings on the new element
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that when using Knockout's text binding, multiple spaces become collapsed into one.
It seems Knockout's convenient afterRender method on foreach bindings only fires when data is
It seems that knockout is not mapping the properties of objects in an array
I'm having a problem with knockout checked binding. It seems that change event at
Most of Knockout seems very intuitive. One thing that is strange to me though
Seems that This will be an easy question for you but this problem is
In attempting to integrate Knockout.js with Select2 , I noticed that what seems to
Overview When creating a knockout custom binding that contains a call to a knockout
This seems to be a common approach to sanitizing/validating/formatting data with knockout when binding
When using knockout, what is the advantage of using read-only computed observables rather than

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.