In my table I have one buttons . In the table I want to disable/enable the entire row with the help of the same button. the button default is enable.
I want to each row all can enable/disable when click the button of the row .
When I click on ‘enable’ button the entire row color will change to red and the button value change to ‘disable’.
click again to the ‘disable’ button , thenthe entire row color recovery and the button value change to ‘enable’.
How to do it . Help needed.
part of my code :
jsfiddle
<table >
<tr>
<th>Value1</td>
<th>Value2</td>
<th>
<input type="button" value="enable" />
</th>
</tr>
<tr>
<th>Value3</td>
<th>Value4</td>
<th>
<input type="button" value="enable" />
</th>
</tr>
</table>
5
Answers
You could change the value of the button and then check if it’s ‘enable’ or ‘disable’
Here’s the code:
Here is my solution:
for changing the color you have to give the class name to the particular rows and in css give the by default color let’s say red color.
To achieve this functionality you can use javascript and jquery.
import the jquery in the script and write the function for toggling the button. This function that takes a button as a parameter. Inside the function, it uses jQuery to find the closest table row element to the clicked button.if the row has the class name which is given in the table then the class is removed and the button value is set to enable and vice versa.
This script will called when the button is clicked and it toggles the appearance of the row and the button text based on the current state.
The previous methods are probably better but here is another option if you use IDs for your rows or buttons.
Try this !