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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:08:28+00:00 2026-05-21T17:08:28+00:00

I’m trying to create a copy/paste system for a HTML table using jQuery and

  • 0

I’m trying to create a copy/paste system for a HTML table using jQuery and a context menu plugin and I’m trying to uniquely name all of the newly created rows. So I have a function that is cloning the selected row and inserting the new row above:

function cloneAbove(TR) {
    var newRow = $(TR).clone();
    var lastID = $(TR).attr('id');
    var newID = Number(lastID.substring(3))-0.1;

    //See if that row already exists:
    if($('#tr_'+newID).length){
    alert('#tr_'+newID+' Exists');
    //If it does exist, we divide the newID by 10 until we find one that doesn't:
    var i = 0;
    while(i < 1){
        newID = newID/10;
        if($('#tr_'+newID).length > 0){
        i = 1;
        }
    }
    }
    $(newRow).attr('id','tr_'+newID);
    $(TR).before(newRow);
    $(".target").contextmenu(option);
}

First it clones the selected row (ie: ‘#tr_1’), subtracts 0.1 for the new row’s id (ie: ‘#tr_0.9’), then it is supposed to check to see if that id already exists – this is where my problem is – if it exists it enters a loop to divide by 10 until it finds a id that doesn’t.

Here is a sample of the table:

<table id="table" border=1>
       <tr class="target" id="tr_1" oncontextmenu="context('tr1')">
           <td id="tr_1_1">Row1</td>
           <td id="tr_1_2">Row1</td>
       </tr>
       <tr class="target" id="tr_2" oncontextmenu="context('tr2')">
           <td id="tr_2_1">Row2</td>
           <td id="tr_2_2">Row2</td>
       </tr>
</table>

The .length works for the ‘hard coded’ elements as they exist when the page loads, but it won’t detect any of the newly created elements. Any suggestions?

  • 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-21T17:08:29+00:00Added an answer on May 21, 2026 at 5:08 pm

    You’re building “id” values that are going to confuse jQuery. The selector “#tr_0.9” means, “find the element with id ‘tr_0’ and class ‘9’”, not “find the element with id ‘tr_0.9′”.

    Setting aside the fact that that strikes me as a pretty weird way to construct “id” values, you may be able to make it work by “quoting” the “.” characters:

    if ($(('#tr_' + newId).replace(/\./g, "\\.")).length) {
      // ... found a duplicate ...
    

    What that does is substitute “.” for “.” in the constructed trial “id” value. You only want to do that, of course, when looking for the elements via a jQuery selector; you don’t want the actual “id” value to have backslashes in it.

    Alternatively, you could replace the “.” characters with “_” or something.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

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.