Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - Getting the text value of a table cell in the same row as a clicked element
    primarykey
    data
    text
    <p>I click a link in a table cell. I need to get the value of a specific cell within this same table row.</p> <pre><code>&lt;tr&gt; &lt;td class="one"&gt;this&lt;/td&gt; &lt;td class="two"&gt;that&lt;/td&gt; &lt;td class="three"&gt;here&lt;/td&gt; &lt;td class="four"&gt;&lt;a href="#"&gt;there&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="one"&gt;qwqw&lt;/td&gt; &lt;td class="two"&gt;dfgh&lt;/td&gt; &lt;td class="three"&gt;ui&lt;/td&gt; &lt;td class="four"&gt;&lt;a href="#"&gt;there&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>I have a click handler attached to the link in the fourth cell. That click handler calls a function that opens a modal window. When a form in the modal is submitted I want to also pass the value of td class="two" from the row in which the link was clicked to this modal. </p> <p>Here is the function that sends the modal (the problem area is getting the correct value for var Something):</p> <pre><code>var Send = function() { var Name = $( '#name' ).val(); var Something = $(this).closest('td').siblings('.two').text(); // version 1. doesn't work var Something = $(this).closest('tr').siblings('td.two').text(); // version 2 also doesn't work var Something = $(this).attr('class'); // version 3. just a test but also doesn't work $.ajax( { async: false, data: { name: Name, somedata: Something }, type: 'POST', url: the url }); }; </code></pre> <p>The problem is that I cannot get the correct value for Something. It should be the value of td class=two in the same row as the clicked element.</p> <p>The way this all comes together is. Click the target link, that calls a method called Send_Click(). Send_Click does some validations and then calls Send() but the value for Something is never populated. Is this because <code>this</code> is not what I'm thinking it is? Hjelp!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload