1
I have a table as follows:
<tabele>
<thead>
<tr>Codigo</tr>
</thead>
<tbody>
<tr class='click-show-hide-tr'>exemplo</tr>
<tr class='click-show-hide-tr'>exemplo</tr>
<tr>exemplo</tr>
<tr class='click-show-hide-tr'>exemplo</tr>
<tr class='click-show-hide-tr'>exemplo</tr>
<tr>exemplo</tr>
<tbody>
</tabele>
I have a script made in Jquery that every click according to the class "click-show-Hide-tr" it Mosta the next "tr" see the script below:
var toggleTable = (function () {
var init = function(){
$(".toggle-table tbody").on('click', '.click-show-hide-tr', function(){
$(this).closest("tr").next().toggle();
});
};
return {
init:init
}
})();
toggleTable.init();
Only I want to hide all the secondary lines by clicking again on the first line without affecting the other lines that are hidden or not Example:
<tabele>
<thead>
<tr>Codigo</tr>
</thead>
<tbody>
/**
* Essa é a linha Principal supondo que as linhas secundarias
* estejam à mostra ao clicar nela de novo
* quero esconder todas elas sem afetar
* as outras linhas
*/
<tr class='click-show-hide-tr'>exemplo</tr>
<tr class='click-show-hide-tr'>exemplo</tr>
<tr>exemplo</tr>
/**
* Esse é outra linha Principal com suas linhas secundarias
* Não posso afetar nada daqui para baixo
*/
<tr class='click-show-hide-tr'>exemplo</tr>
<tr class='click-show-hide-tr'>exemplo</tr>
<tr>exemplo</tr>
<tbody>
</tabele>
I’m still having problems, when I click on any other line all daughter lines are hidden...
– Lucas Lima
try to use
$(".selecionado tr:first-child");
instead of$(".click-show-hide-tr.selecionado").next();
– Gabplay
I got it right here !
– Lucas Lima