Note that there are some explanatory texts on larger screens.

plurals
  1. POassign multiple element attributes with .each?
    primarykey
    data
    text
    <p>So I have the following table, and I'd like to set all the name attributes to a new value when I add a row to the table. (You probably guessed it: I use the buttons to add and delete rows, and I calculate a new name attribute based on the row index).</p> <pre><code>&lt;table id="orderstable" &gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="top"&gt;&lt;img src="/images/images/add_button_sm.gif" id="add_" align="top" border="0"&gt; &lt;img src="/images/images/delete_button_sm.gif" id="del_" border="0"&gt; &lt;/td&gt; &lt;td&gt;&lt;input name="orderBoxes[0].A" size="3" value="0.0" type="text"&gt;&lt;/td&gt; &lt;td&gt;&lt;input name="orderBoxes[0].B" size="3" value="0.0" type="text"&gt;&lt;/td&gt; &lt;td&gt;&lt;input name="orderBoxes[0].C" size="3" value="0.0" type="text"&gt;&lt;/td&gt; &lt;td&gt;&lt;select name="orderBoxes[0].D"&gt; &lt;option value="fifty"&gt;50&lt;/option&gt; &lt;option value="oneHundred" selected="selected"&gt;100&lt;/option&gt; &lt;option value="twoHundred"&gt;200&lt;/option&gt; &lt;option value="threeHundred"&gt;300&lt;/option&gt;&lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>I've tried to use .each to get all the elements and then get at the input.name attribbute.... but I can't get it to work. Any thoughts? My code may not be the most efficient... I'm still a noob:</p> <pre><code>$("#orderstable &gt; tbody &gt; tr &gt; td &gt; img[id=add_]").click( function(event){ var row = $(this).closest("tr").get(0); var rowCopy=$(row).clone(true); $(row).closest("tbody").append(rowCopy); $('#orderstable tbody&gt;tr:last&gt;td').each(function(){ $(this.input).attr(name); }).val = "test"; row.className+="add_"; </code></pre>
    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.
    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