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 6198687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:03:36+00:00 2026-05-24T04:03:36+00:00

I have a template like this: <script id=notesTemplate type=text/html> <li class=Note> <div class=NoteDate data-bind=style:

  • 0

I have a template like this:

<script id="notesTemplate" type="text/html">
<li class="Note">
    <div class="NoteDate" data-bind="style: { backgroundColor: background, color: color}">
            <span data-bind="text: date"></span>
        </div>
        <div class="NoteRight" data-bind="style: { backgroundColor: background, color: color}">
            <div class="NoteContent">
                <span data-bind="text: content"></span>
            </div>
            <div class="line" data-bind="style: { borderColor: color}"></div>
            <div class="NoteCategory" data-bind="style: { color: color}">
                <span data-bind="text: category"></span>
            </div>
        </div>
</li>
</script>

As you see, I create a simple list with notes (I set some css styles because every note item have its own bg and color but, is this the right way?) but:

I want to set the NoteDate div with height equal to the NoteRight div. I’m actually doing that in JS:

$(function () {
    ko.applyBindings(new viewModel());

    $(".Note").each(function (index, element) {
        var date = $(element).find(".NoteDate");
        var note = $(element).find(".NoteRight");

        date.height(note.height());
    });
});

But this is kinda slow because the notes are retrieved using Ajax and I have to do that call with async: false or the notes will not be fetched before the “each” runs.

So: It’s possible to “translate” that code to the template? I tried something like:

<div class="NoteDate" 
     data-bind="style: { backgroundColor: background, 
                         color: color, height: $('.NoteRight').height() }">

But that doesn’t work.

After even some more fiddling around, I have this function now (afterRender):

this.updateNotesLayout = function (elements) {
    var date = $(elements).find(".NoteDate");
    var note = $(elements).find(".NoteRight");
    alert(date.height());
    alert(note.height());
    date.height(note.height());
    alert(date.height());
}

But the date and note height is 0, but in the old example, the height was correct on both cases.

Any idea?

  • 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-05-24T04:03:37+00:00Added an answer on May 24, 2026 at 4:03 am

    The easiest option to run code against elements rendered by a template is to use the afterRender callback of the template binding.

    http://knockoutjs.com/documentation/template-binding.html#note_4_using_the__option

    This will allow you to run code on your new nodes. In a foreach situation this runs for each item.

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

Sidebar

Related Questions

Let's say I have a template like this <script id=rowTemplate type=text/x-jquery-tmpl> <tr> <a href=${
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
Suppose I have code like this: template<class T, T initial_t> class Bar { //
I have code like this: template <typename T, typename U> struct MyStruct { T
I have this tiny Qt project with a project file like this: TEMPLATE =
I have an xml that looks like this: <Config> <A></A> <Template><B/><C/></Template> </Config> and I
I would like to have a nice template for doing this in development. How
I have a template class like below. template<int S> class A { private: char
I have a ruby cgi script which writes it output like this: cgi.out(Cache-Control =>
I have a django form on my template like this: <form action=/my-page/ method=post name=my_form>{%

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.