Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect inputs in first row of table
    primarykey
    data
    text
    <p>I have page that I'm working on that contains a table with a header row, several rows of text inputs, and a total row. When a user enters numbers in the inputs, the sum of each column is calculated in the totals row. This calculation is run when an input's <code>change()</code> event is fired.</p> <p>When the page is loaded, I'd like to be able to trigger a <code>change()</code> event on the text inputs in the first row of the table. I'm having some trouble figuring out the correct selector to use.</p> <p>Exampe of table structure:</p> <pre><code>&lt;table&gt; &lt;tr class="tblRow headerRow"&gt; &lt;!-- header cells --&gt; &lt;/tr&gt; &lt;tr class="altTblRow"&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input1-1"&gt; &lt;/td&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input1-2"&gt; &lt;/td&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input1-3"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr class="tblRow"&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input2-1"&gt; &lt;/td&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input2-2"&gt; &lt;/td&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input2-3"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr class="tblRow"&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input3-1"&gt; &lt;/td&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input3-2"&gt; &lt;/td&gt; &lt;td class="tableCell"&gt; &lt;input type="text" id="input3-3"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr class="altTblRow totalRow"&gt; &lt;!-- total cells --&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>I tried using a couple of selectors, but haven't been able to get what I'm looking for.</p> <pre><code>$('.tblRow:first input').change(); $('.tblRow input').first().change(); $('.tblRow input').parent('tr').find('input').change(); </code></pre> <p>Is there a selector that I can use for just the inputs in the first table row, or do I have to get the first <code>input</code> and get the row using <code>.parent()</code>?</p> <p><em>(Note: ID's have been changed in the code sample; otherwise I'd use <code>'input[class*=input1]'</code>)</em></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