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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:16:12+00:00 2026-06-05T00:16:12+00:00

I have a table in my page as below; <table id=tbl cellpadding=0 cellspacing=0 style=width:

  • 0

I have a table in my page as below;

<table id="tbl" cellpadding="0" cellspacing="0" style="width: 100%">
  <tr>
    <td class="field1s">field1x</td>
    <td class="field2s">field2x</td>
    <td class="field3s">field3x</td>
    <td class="field4s">field4x</td>
    <td class="xx">#</td>
  </tr>
</table>

The table contains so many rows. When I click last cell (xx), I want all other texts in the row change to <input type="text" /> having corresponding classes respectively, with their corresponding texts inside. And when user again click xx, the row may be updated with changed text.

I caught data and made some work already.

Here is the fiddle

  • 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-05T00:16:15+00:00Added an answer on June 5, 2026 at 12:16 am

    I’d suggest the following:

    $('#tbl').on('click','.xx',function() {
        $(this).siblings().each(
            function(){
                // if the td elements contain any input tag
                if ($(this).find('input').length){
                    // sets the text content of the tag equal to the value of the input
                    $(this).text($(this).find('input').val());
                }
                else {
                    // removes the text, appends an input and sets the value to the text-value
                    var t = $(this).text();
                    $(this).html($('<input />',{'value' : t}).val(t));
                }
            });
    });
    

    JS Fiddle demo.


    Edited in response to comments from @mplungjan (below):

    .text(something) must surely be faster and simpler to read than .text("").append(something) in any case. And you are not adding text but html so even more reason to use just html().

    He’s right, of course. Therefore:

    $('#tbl').on('click','.xx',function() {
        $(this).siblings().each(
            function(){
                if ($(this).find('input').length){
                    $(this).text($(this).find('input').val());
                }
                else {
                    var t = $(this).text();
                    $(this).html($('<input />',{'value' : t}).val(t));
                }
            });
    });
    

    JS Fiddle demo.

    References:

    • append().
    • each().
    • find().
    • siblings().
    • text().
    • val().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in my page as below. <table id=tbl> <tr> <td class=field
I have the following table in my page <table> <tr class=evenPack> </tr> <tr class=evenSubPack>
I have a html page as below: <div id=test1> <table> <tr> <td><span id=234>ABKO</span></td> </tr>
I have a page with a fixed header and below that a table that
I have a db with two tables like these below, page table pg_id title
I have a <code>rich:extendedDataTable</code>. Each row has a a4j:commandLink as below. Table Page: <a4j:commandLink
In the code below (jsf page), i have some hotel info in display:table rows
I have this page table below and I want to remove the numbering prefix
I have an html table rendered page and I want to save it as
I have a table on near the bottom of the page, which I want

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.