Clem Clem - 2 months ago 8
jQuery Question

Table rows show/hide - remove()

My question is, why I can not use

hide()
&
show()
to hide/show table rows on my web page. Browser freezes if I use any of those, but if I use
remove()
it works fine, but then I cannot get this row back(or?).

If I use show and hide on any other thing's it work's just fine. What did I do wrong?

for(var i=0; i<=pages-begin; i=i+1){
if($("#myTable2 tr:nth-child("+i+") td:nth-child("+ rowIndex +")").text() == $(this).text()){
$("#myTable2 tr:nth-child("+i+") td:nth-child("+ rowIndex +")").parent().remove(); i=i-1;}
}


EDIT:

I used
live()
, and as I read just now toggle and such do not work inside
live()
... but I still need answer :(

$("#dropMenuFilter ul li").live("click", function(){
for(var i=0; i<=strani-zacetek; i=i+1){
if($("#myTable2 tr:nth-child("+i+") td:nth-child("+ rowIndex +")").text() == $(this).text()){
$("#myTable2 tr:nth-child("+i+") td:nth-child("+ rowIndex +")").parent().fadeOut(); i=i-1;}
}});


dropMenuFilter is some div, on which I append
.text()
of specific
<td>
and I wish, that when I click on it, it will remove parent of this td: table row. It works with
remove()
...

Answer

soloution:

function removeRow(vrstica){
    $("#myTable2 tr:nth-child("+vrstica+") td:nth-child("+ rowIndex +")").parent().toggle();
}

$("#dropMenuFilter ul li").live("click", function(){
    for(var i=1; i<=strani-zacetek; i+=1){
        if($("#myTable2 tr:nth-child("+i+") td:nth-child("+ rowIndex +")").text() == $(this).text()){
            removeRow(i);
        }
    }
})
Comments