How to obtain text of a <td> element from another <td> element with jquery

Related searches

I am trying to use a button inside a table division to set a variable as the same value as another division in the same row, but whenever I run my code (below), it returns the value of all the table divisions concatenated together. I am unsure why this was happening, so I replaced '.children()' with 'childnodes[0]' to try and get only the first name, but this just doesn't work and I don't why.

My html looks like this:

  <table>
    <tr>
      <td>John</td>
      <td>Doe</td>
      <td><button>Get First Name</button></td>
    </tr>
  </table>

And my Javascript is this:

$(document).ready(function(){
    $("button").click(function(){
      var first = $(this).closest("tr").childNodes[0].text();
      alert(first)
        })
    });

set a variable as the same value as another division in the same row

there are lots of possibilities for this, here are some (with the most useful first (opinion based))

$("button").click(function() {
  var first = $(this).closest("tr").find("td:first").text();
  var first = $(this).closest("tr").find("td").first().text();
  var first = $(this).closest("tr").find("td").eq(0).text();

  var first = $(this).closest("tr").children().first().text();
  var first = $(this).closest("tr").children().eq(0).text();

  var first = $(this).closest("td").siblings().first().text();
});

it returns the value of all the table cells concatenated together

https://api.jquery.com/text

Get the combined text contents of each element in the set of matched elements, including their descendants, or set the text contents of the matched elements.

because you're passing the "tr" to text() it gets the text of all the cells (tds) and their content etc and combines them as one, so you need to limit to the first as you've attempted.

however .childNodes[0] can only be applied to a DOM element/node, while $(this).closest("tr") gives you a jquery object/collection, which doesn't have .childNodes property.

So the jquery equivalent would be to use .children().eq(0).

How to Get Text Message History From Phone, The first way is to look in your cell phone messaging inbox and outbox. Unless you erase a message, your phone keeps track of all your text messages. The other� Obtaining AT&T text message records depends on how a user’s account and phone are set up. According to the Department of Justice, as of 2010, AT&T does not retain the content of text messages. The company may hold onto some text message detail, such as phone numbers texted, for only five to seven years.

You could use class identifiers to get information you need as well.

<table>
  <tr>
    <td><span class="first-name">John</span></td>
    <td><span class="last-name">Doe</span></td>
    <td>
      <button class="btn-get-data" data-class="first-name">Get First Name</button>
      <button class="btn-get-data" data-class="last-name">Get Last Name</button>
    </td>
  </tr>
</table>


$(document).ready(function() {
  $(".btn-get-data").click(function() {
    $btn = $(this);
    $tr = $btn.closest('tr');
    var first = $tr.find('.' + $btn.attr('data-class')).html();
    alert(first);
  })
});

If you make the button click generic like so, you can add additional buttons on the page and use that to get the class within that row.

Here is a working fiddle example: https://jsfiddle.net/b1r0nucq/

How to Get Cell Phone Text Message Records, In order to get the usage data about the text messages sent from your phone, fill out the consent form and submit it to Sprint. It must be notarized� How to capture text on Windows or Mac Step 1: Set up your capture settings To capture text, open the Capture Window, select the Image tab, and set the Step 2: Capture your screen Initiate your capture, then use the crosshairs to select the region of your screen with the Step 3: Paste your text

you could find the :first child and get his html(), as below:

$(document).ready(function() {
  $("button").click(function() {
    var first = $(this).closest("tr").children(":first").html();
    alert(first)
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td><button>Get First Name</button></td>
  </tr>
</table>

Send & get text messages - Android, Send & get text messages. For Voice for G Suite accounts managed by your work or school, text messaging is available only in the U.S.. You can send text� Re: How to obtain text of a view definition 3049977 Mar 8, 2016 5:18 PM ( in response to SomeoneElse ) To clarify: The program that I am working on needs to determine that the view definition is the same as the last time it ran.

Send & get text messages - Computer, Send & get text messages. For Voice for G Suite accounts managed by your work or school, text messaging is available only in the U.S.. You can send text� How to Print Text Messages from Android Phone. Steps of Recovering Text Message Records from Android. Step 1. Connect device to desktop and make it be recognized by the program. (To restore Android text messages, the Android device is required to be rooted, and USB debugging on your Android phone also should be opened.) Step 2.

How to Get Text Message Records from iOS/Android Phones- Dr.Fone, This article explains how you can recover the deleted text messages from your phone and how to get text message records from the phone. It supports to recover text message records without backup. Extract and recover text message records you need from iTunes or iCloud without having to restore the whole backup. 1. Steps to Get iPhone Text Message Records from iPhone Directly without Backup. 1. Open iMyFone D-Back and select “Recover from iOS Device” on the left. Click on

A short code text is one way that a company can market new services or products to its customers. Register and obtain your short code with the Common Short Code Administration. This organization handles the registration on your short code number and ensures that your code works for all cell phone carriers associated with the CSCA.

Comments
  • check this answer stackoverflow.com/questions/2931234/…