pass table row to another with jquery


Hi, I'm making a table that shows the contents of my database.

I am using this code: Jquery 1.4.2

    $(function() {
   function moveRow(row, targetTable, newLinkText){

   $("#idfirst a").live("click", function(){
       moveRow($(this).parents("tr"), $("#idsecond"), " Agregar");

   $("#idsecond a").live("click", function(){
       moveRow($(this).parents("tr"), $("#idfirst"), " Eliminar");


And my table:

    <div id="table-wrapper">
        <div id="table-scroll">
            <table id="idsecond" class="table table-bordered table-hover">

                        <th>Unidad M.</th>

                            if ($result2->num_rows > 0) {

                                while($row = $result2->fetch_assoc()) {

                            echo '<tr><td>'.$row["nombre"].
                            '</td><td>S/ '.$row["precio"].
                            '</td><td><img height="100" width="100" src="php/'.$row["imagen"].'" alt="img01" />
                            <button type="button" id="idbtnagregar" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-plus" ></i>
                            <a href="#" style="text-decoration:none;color:white;">&nbsp;Agregar</a>

                            } else {
                                echo "0 results";


What the jquery code does is to pass data from one table ( idsecond ) to another table ( idfirst ):

<table id="idfirst" class="table table-bordered table-hover">
// Se agregan de otra tabla
//ademas que se genera el botón de eliminar, para cada fila

The problem is that I want the delete button to change its background-color when it is to delete, and I also add a column with an input text for each row.

I would also like to know how you could do that by entering a value in each text field, calculate a total (multiplying what is entered in the text field and the unit price P.Unitary of each row) and It shows in another row. To later enter it in my database.

Any ideas on how to do it? Thanks in advance.

asked by Raphael 21.06.2016 в 13:59

1 answer


To change the background color of a button to jquery, you can do it in two ways:

1- Using the Jquery css property:

$("#idBoton").css( "background-color", "red" );

2- Adding and removing classes with Jquery

$("#idBoton").addClass( "fondo-rojo" );
$("#idBoton").removeClass( "fondo-rojo" );

I hope it serves you

answered by 21.06.2016 / 14:22