My question is very simple. I want to display only the content of one tr at a time. That means when I click on the other tr then the other opened tr should get closed.
My code is as below
<head>
<style>
p { width:400px; }
.click{cursor:pointer;}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
function visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}
</script>
</head>
Above is the head section where onClick a function called visibility is getting called. Below in the body section I am trying to display two tr using for loop.
<body>
<table>
<?php
$i=2;
for($i = 1; $i <= 2; $i++)
{
?>
<tr class="click <?php echo $i; ?>" onClick="visibility('<?php echo $i; ?>');">
<td>Click <?php echo $i; ?></td>
</tr>
<tr id="<?php echo $i; ?>" style="display:none;">
<td>This is a paragraph <?php echo $i; ?></td>
</tr>
<?php
}
?>
</table>
</body>
I am unable to get the desired result(That means only one tr should be visible at a time). There are many existing Jquery plugins available but I do not want to use them as it will increase the load on my web page and so much of customization will be required. I am almost done and hoping to get the desired result with the help from you all. Thanks in advance