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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:48:20+00:00 2026-05-29T03:48:20+00:00

jsfiddle: http://jsfiddle.net/mAF6A/3/ I’m cloning a template TR in a table, setting a $.data() attribute

  • 0

jsfiddle: http://jsfiddle.net/mAF6A/3/

I’m cloning a template TR in a table, setting a $.data() attribute of the clone and appending it to the table. After I append it, it looses the data attribute though. What am I doing wrong here?

var arr = [{
    name: "one",
    id: 1},
{
    name: "two",
    id: 2},
{
    name: "three",
    id: 3}];

$.each(arr, function(i, item) {
    var clone = $("tr.template").clone().removeClass("template");
    clone.find(".value").html(item.name);
    clone.data("number", item.id);
    clone.find(".data").html("My data is: " + clone.data("number"));
    $("table").append(clone);
});

$("tr[data-number='2']").remove();
  • 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-29T03:48:20+00:00Added an answer on May 29, 2026 at 3:48 am
    clone.data("number", item.id);
    

    This does not add a data- attribute to the element. It stores it in jQuery’s internal “data” object.

    You need to actually add the attribute to the element.

    clone.attr("data-number", item.id);
    

    The data method can read data- attributes, but it can’t write them.

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

Sidebar

Related Questions

jsfiddle: http://jsfiddle.net/UenFN/ . Notice the slight, brief pixelation after the animation. This error only
In this jsfiddle http://jsfiddle.net/littlesandra88/eGRRb/ have I submit buttons that are auto-generated. Each table row
jsFiddle: http://jsfiddle.net/Mw4j2/6/ Trying to change attributes to a selector if the seconds count is
Relevent jsFiddle: http://jsfiddle.net/julianlam/eLs9E/ For some reason, given the dataset shown in the fiddle, when
Here is the JSfiddle: http://jsfiddle.net/buyC9/128/ I want to clear only the file upload field
I have a jsfiddle http://jsfiddle.net/4Pc4B/10/ . In the jsfiddle, type in a question in
Link to jsfiddle: http://jsfiddle.net/crismanNoble/gqFdH/2/ Basically the svg keeps changing colors without ever triggering the
Ok so here is my jsfiddle - http://jsfiddle.net/8947F/ basically the slideToggle seems to add
I have some sort of elsif statment bug I can't find: My JSfiddle: http://jsfiddle.net/z3xV3/64/
Why isn't jQuery being applied to dynamically created elements? Here is jsFiddle: http://jsfiddle.net/Y5RuC/19/ When

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.