Click here to Skip to main content
15,889,732 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table which have 10 rows and there is a button.
i have to hide all rows except the firts row, for the first time.
and when i click on that button each row has to be displayed.

i have written the code as follows

C#
i = 1;
$(document).ready(function () {


    $('#Tr2').hide();
    $('#Tr3').hide();
    $('#Tr4').hide();
    $('#Tr5').hide();
    $('#Tr6').hide();
    $('#Tr7').hide();
    $('#Tr8').hide();
    $('#Tr9').hide();
    $('#Tr10').hide();


});

$('#NewRecord').click(function () {

    if ($.cookie('Value') == null) {
        jQuery.cookie('Value', 1);
    }
    else {
        i = parseInt(jQuery.cookie('Value'));
    }
    i = i + 1;
    jQuery.cookie('Value', i);

    if (i >= 2) {
        $('#Tr2').show();
    }
    else {
        $('#Tr2').hide();
    }
    if (i >= 3) {
        $('#Tr3').show();
    }
    else {
        $('#Tr3').hide();
    }
    if (i >= 4) {
        $('#Tr4').show();
    }
    else {
        $('#Tr4').hide();
    }
    if (i >= 5) {
        $('#Tr5').show();
    }
    else {
        $('#Tr5').hide();
    }
    if (i >= 6) {
        $('#Tr6').show();
    }
    else {
        $('#Tr6').hide();
    }
    if (i >= 7) {
        $('#Tr7').show();
    }
    else {
        $('#Tr7').hide();
    }
    if (i == 8) {
        $('#Tr8').show();
    }
    else {
        $('#Tr8').hide();
    }


});

where Tr2...Tr10 are the row id's.

But it is not working properly
Posted
Comments
jim lahey 18-Apr-12 4:49am    
what isn't working properly?

1 solution

I think ,this is what you want...
XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>
<style type="text/css">

a#click , a#click_hide
{
cursor:pointer;
padding:3px 5px;
background-color:#CCCCFF;
}
.content
{
border:solid 1px #993333;
}
.show
{
display:block;
}
.hide
{
display:none;
}

</style>

<script type="text/javascript">

$(window).ready(function (){
$(".content").addClass("hide");
$(".content:first").removeClass("hide").addClass("show");

$("#click").click(function(){
    if($('.show').next().hasClass('content'))
    {

    $(".show").next().removeClass("hide").addClass("show");
    }
});

$("#click_hide").click(function(){

    if($('.show:last').hasClass('content'))
    {
        if($('.show:last').get(0)===$('.show:first').get(0))
        {
        }
        else
        {
            $(".show:last").removeClass("show").addClass("hide");
        }
    }
});

});

</script>
</head>
<body>
<div style="width:180px; margin:0px auto;">

    <div style="border:solid 1px #CC3300; width:100%; height:90px;">
        <div style="text-align:center;">
            <a id="click">Show it...</a>
        </div>
        <div style="text-align:center; padding-top:15px;">
            <a id="click_hide">Hide it...</a>
        </div>
    </div>

    <div class="content">

        <h1 align="center"> Content 1 </h1>

    </div>
    <div class="content">

        <h1 align="center"> Content 2 </h1>

    </div>
    <div class="content">

        <h1 align="center"> Content 3 </h1>

    </div>
    <div class="content">

        <h1 align="center"> Content 4 </h1>

    </div>
    <div class="content">

        <h1 align="center"> Content 5 </h1>

    </div>

</div>

</body>
</html>


It will rock upto

<div class="content">

        <h1 align="center"> Content N... </h1>

</div>
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900