Hide a table after clicking

Asked

Viewed 36 times

0

I have a table that lists the customers of a company. The user selects the client he wants through the links in each. By clicking the table data feed the form inputs. Only now I want to hide the table, since the user has already selected the record that would like.

The table I list so:

<table class="table" id="tabelaCliente">

        <tbody>
        <tr>
            <th>
                <i>
                    Cliente
                </i>
            </th>
            <th>
                <i>
                    Telefone
                </i>
            </th>
        </tr>
        <?php
        foreach ($query as $linha) {
        ?>
            <tr>
                <td id="<?php echo $linha->id ?>"> <a href=""><?php echo $linha->nome ?></a></td>
                <td><?php echo $linha->telefone . ' ou ' . $linha->celular ?></td>
            </tr>
        <?php
        }
        ?>
        </tbody>
</table>

To feed form inputs I use AJAX:

$(document).on("click","#tabelaCliente td a",function(e){
    e.preventDefault()
    var id_cliente = $(this).parent().attr("id");

    $('#nome').val($(this).text());
   // para ocultar eu faço
    $('#tabelaCliente').hide('slow');
    // já tentei isso também
   // document.getElementById('tabelaCliente').style.display = "block";

});

My problem is in hiding the table, it won’t... Does anyone know how to do?

  • 1

    Try $("#tableClient"). css("display", "None"); and to display it again if you need $("#tableClient"). css("display", "block"); ie None hides and block displays.

  • Thanks, it worked out

  • Quiet Rafa, luck there !

1 answer

0

I think that that answer is just what you need:

$('#tabelaCliente td a').click(function() {
    //o que precisar fazer..

    $('#tabelaCliente').toggle('slow');
});
  • Best edit and place your code within $( Document ).ready(Function() {} so there are no errors if the gift has not been fully loaded!

  • Thanks @rLinhares, but not yet hidden.

  • @Rafaelsalomão should really stay inside the ready, but the idea was to leave in the answer only the same Function, not the whole code.

  • https://jsfiddle.net/m15h14k7/, I took the code of the Inhares that works, and I set the example. Look at it working. You’re doing something wrong!

  • Tranquil @rlinhares!

  • @Rafaelchristófano I think the problem is this structure (tabelaCliente td a) that should not be correct; see the html generated if it would be this way.

  • Yes, the structure is this: I have the table id="tableClient, then it follows the table header, then I make a loop displaying the data in a <tr><td>, the contents of the cells <td> have an Ink <a>

  • the above comment from @Rafaelsalomao, right after my question worked. I hadn’t seen it before. Thank you all

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.