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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:24:41+00:00 2026-05-31T20:24:41+00:00

I have set the data to div element and append it to another div

  • 0

I have set the data to div element and append it to another div element like this,

var dt = { id: 0 };
$.template("temp", '<div id="div2" >${id}</div>');
$.tmpl("temp", dt).appendTo("#div1");

Its working fine. I am appending it in document ready method.

My requirement is, Its(div2) click event i have to access dt.

Is it possible?

Question 2: i have set this data to a lot of elements. How to get those elements?

Thanks in advance.

  • 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-31T20:24:42+00:00Added an answer on May 31, 2026 at 8:24 pm

    You can use $.tmplItem:

    var dt = { id: 222, text: 'My value id 222' };
    
    $.template("temp", '<div class="innerDiv" >${id}</div>');
    $.tmpl("temp", dt).appendTo("#div1");
    
    $(document).on('click', '.innerDiv', function() {
        // gets the data item associated to the rendered template
        var dataItem = $.tmplItem(this);
        // dataItem.data holds the data itself
        alert(dataItem.data.text);
    });
    ​
    

    DEMO


    For the second question, I don’t know a way to easily get the list of renderings of a specific template with the API.

    What you could do though is to add a data- attribute to your template markup which would allow you to retrieve them easily:

    $.template("temp", '<div id="div2" data-tmpl="temp">${id}</div>');
    

    Then you can select all renderings which has an attribute “data-tmpl” with value “temp”:

    $('[data-tmpl="temp"]')
    

    I have updated the demo in that way.

    Maybe there is some other way but I’m that familiar with jQuery template.

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

Sidebar

Related Questions

I have a template like this: <script id=notesTemplate type=text/html> <li class=Note> <div class=NoteDate data-bind=style:
I have a set of data that is structured like this: ItemA.GroupA ItemB.GroupA ItemC.GroupB
We have this set of data that we need to get the average of
I have a set of data, with columns x and y. This set contains
I have my datepicker set up like this $(#scheduled_date_163).datepicker({ onSelect: function(dateText, inst) { jQuery.get(/tasks/inplace_edit?id=scheduled_date_163&class_name=Task&value=
I have this simple project to grab HTML element inner data. This is a
I have a small set of structured data items that I would like embedded
I have a set of data that models a hierarchy of categories. A root
I have a set of data protected by 16bit checksums that I need to
I have a set of data that needs to be displayed as a crosstab

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.