Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to hide all the rows in the html table except first two and last row using Jquery
Posted

1 solution

Try with below code:
HTML
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){		
        // Hide first two rows
		$("#table1 tr:lt(2)").hide();

        // Hide last row
        $( "#table1 tr:last").hide();
    });
});
</script>
</head>
<body>
<table id="table1">
	<tr>
		<td style="text-align:center;">ghj1</td>
	</tr>
	<tr>
		<td style="text-align:center;">fgh2</td>
	</tr>
	<tr>
		<td style="text-align:center;">n3</td>
	</tr>
	<tr>
		<td style="text-align:center;">xcv4</td>
	</tr>
	<tr>
		<td style="text-align:center;">dsgf5</td>
	</tr>
</table>
<button>Click me</button>
</body>
</html>
 
Share this answer
 
v2

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