Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Adding a Column before last Column

Tags:

html

jquery

I'm trying to create a new column when I press the "+" button.

The problem that I have is:

I click the button and it generate a column after the last one. How Can I do it for generate it before?

I put my table here:

<table>
   <tr>
      <td><input value = "0"/></td>
      <td><input value = "0"/></td>
      <td><input value = "0"/></td>
      <td class="total">0</td>
   </tr>
   <tr>
      <td><input value = "0"/></td>
      <td><input value = "0"/></td>
      <td><input value = "0"/></td>
      <td class="total">0</td>
   </tr>
   <tr>
      <td><input value = "0"/></td>
      <td><input value = "0"/></td>
      <td><input value = "0"/></td>
      <td class="total">0</td>
   </tr>
</table>

Thats the code that I have for the moment:

http://jsfiddle.net/2G7Lh/

Thank you very much!

like image 318
Funereal Avatar asked May 05 '26 23:05

Funereal


1 Answers

Try

$("tr").find("td:last").before('<td><input type="text" value=""></td>');

Fiddle Demo

.find() the :last td in each tr than insert the element .before() it.


You've a Typo too missing =

change <input type"text" to <input type="text" as commented by Biduleohm

like image 121
Tushar Gupta - curioustushar Avatar answered May 08 '26 14:05

Tushar Gupta - curioustushar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!