Given the below HTML
table, I would like to hide columns when their checkboxes are un-checked and show them when the boxes are checked then save the preference of hiding or showing the columns so that when the page reloads, the columns are shown or hidden based on the preference.
How can I do this using jQuery
? Do I need to use cookies
?
<table>
<thead>
<td>
<input type="checkbox" checked="checked" id="opt1" />
</td>
<td>
<input type="checkbox" checked="checked" id="opt2" />
</td>
<td>
<input type="checkbox" checked="checked" id="opt3" />
</td>
<td>
<input type="checkbox" checked="checked" id="opt4" />
</td>
<td>
<input type="checkbox" checked="checked" id="opt5" />
</td>
</thead>
<tbody>
<tr>
<td>column 1</td>
<td>column 2</td>
<td>column 3</td>
<td>column 4</td>
<td>column 5</td>
</tr>
<tr>
<td>column 1</td>
<td>column 2</td>
<td>column 3</td>
<td>column 4</td>
<td>column 5</td>
</tr>
<tr>
<td>column 1</td>
<td>column 2</td>
<td>column 3</td>
<td>column 4</td>
<td>column 5</td>
</tr>
<tr>
<td>column 1</td>
<td>column 2</td>
<td>column 3</td>
<td>column 4</td>
<td>column 5</td>
</tr>
</tbody>
</table>