Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My first thoughts of an approach to this problem:</p> <pre><code>$('.testJQuery').each(function() { $(this).click(function(event) { var values = {}; // creating an object // looking at all table rows except for the one containing the button $('tr').not($(this).closest('tr')).each( function(){ // the first 'label' is the label-text l = $(this).find('label:eq(0)').text(); // the second 'label' is the value (for some reason) v = $(this).find('label:eq(1)').text(); values[l] = v; }); // using the console to allow for exploration of the returned object console.log(values); // just to prevent submission return false; }); }); </code></pre> <p><a href="http://jsfiddle.net/davidThomas/WMdDZ/1/" rel="nofollow">JS Fiddle demo</a>.</p> <p>This approach is somewhat unwieldy, given that it has to look at <em>every</em> table-row and then look for <code>label</code>s. In your finished version will there be one label-value pair per table? Or multiples?</p> <p>If there's more than one pair per table what do you want to happen?</p> <p>Incidentally, a <code>label</code> is used to uniquely identify an associated input element in a form; if you don't have an associated <code>input</code> you're using <code>label</code>s incorrectly. If you used, instead:</p> <pre><code>&lt;td class="labelValuePairs"&gt; &lt;span class="label"&gt;ParamB:&lt;/span&gt; &lt;span class="value"&gt;ParamB value&lt;/span&gt; &lt;/td&gt; </code></pre> <p>It becomes slightly easier to work with, for example:</p> <pre><code>$('.testJQuery').each(function() { $(this).click(function(event) { var table = $(this).closest('table'), labelText = table.find('.labelValuePairs span.label').text(), valueText = table.find('.labelValuePairs span.value').text(); alert(labelText + ' ' + valueText); return false; }); }); </code></pre> <p><a href="http://jsfiddle.net/davidThomas/WMdDZ/2/" rel="nofollow">JS Fiddle demo</a>.</p> <p>It's worth noting that you don't need to iterate over the <code>$('.testJQuery')</code> elements with <code>each()</code>, the <code>click()</code> method will apply to all elements returned by the selector. The above, then, can be reduced to:</p> <pre><code>$('.testJQuery').click(function(event) { var table = $(this).closest('table'), labelText = table.find('.labelValuePairs span.label').text(), valueText = table.find('.labelValuePairs span.value').text(); alert(labelText + ' ' + valueText); return false; }); </code></pre> <p><a href="http://jsfiddle.net/davidThomas/WMdDZ/3/" rel="nofollow">JS Fiddle demo</a>.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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