After struggling with a question I posted yesterday about creating a "Button That When Clicked Will Display Hidden Column in HTML Table", I decided to take a different approach. Here's what I came up with:
- I developed a button that, upon clicking, will add a new class to an element
- This new class will allow us to toggle the visibility of a column using the 'display' property in CSS
Here's the structure of the HTML element:
echo "<td class =\"development\" id = 'tag$i'>test1</th>";
echo "<td class =\"development\" id = 'tag$i'>test2</th>";
echo "<td class =\"development\" id = 'tag$i'>test3</th>";
The variable $i represents the row number. Picture each of these <td>
elements being generated within a loop to form a column.
In terms of CSS styling:
.development{
text-align:center;
padding-left:10px;
display:block;
}
.hide{
display:none;
}
Now, this is where I could use some assistance. I'm suggesting a button that, when clicked, triggers a JavaScript function to apply the '.hide' class to the <td>
tags.
<button onclick="addCss()">Click me</button>
I'm uncertain about how to write the JavaScript code and whether I need to pass any parameters such as the ids for the <td>
tags.