behzad razzaqi
behzad razzaqi

Reputation: 147

How can i toggle table tr with jquery?

I create this table with razor in asp.net mvc:

...some code...
                @{
                    int counter = 0;
                    foreach (var item in ViewBag.CdrDetail)
                    {
                        counter++;

                        <tr class="success" id=@counter>
                            <td>@counter</td>
                            <td>@item.calledCity</td>
                            <td>@item.Duration</td>
                            <td>@item.Price</td>
                            <td>@item.persianDate</td>
                            <td>@item.perianTime</td>
                            <td>@item.strDestination</td>
                        </tr>
                    }

                }
...some code...


and write this jquery code for toggle tr with id:

$('#UL li').click(function (e) {
                alert(this.id);
                for (i = this.id; i < $("#MaxValue").val() ; i++) {

                    $('#CDRTABLE .'+i).toggle();
                }
            });


but don't toggle ,how can i solve that problem?thanks

Upvotes: 1

Views: 331

Answers (1)

ebram khalil
ebram khalil

Reputation: 8321

I think you got confused between Class and ID selectors:

In your code for the table rows you are setting the id property through id=@counter (whihc is a bad idea and semantically very wrong), while in your JS code you are using class selector $('#CDRTABLE .'+i).toggle(); // see that .

So, either change your html code to be class="success @counter"

OR, change your JS code to be $('#CDRTABLE #'+i).toggle(); // # not .

Upvotes: 1

Related Questions