Tried a few different methods, without success, so I hope someone can help, I dropped the code below so that it is the most basic (and non-functional), basically what I need, I will have heaps of table rows as well as shown below, but I want each checkbox action to trigger a switch on the closest set of items <span>.
Code below:
$(document).ready(function() {
$("input#change").change(function() {
$("span.disabled").toggle();
$("span.enabled").toggle();
$("span.pending").toggle();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form action="page.php" method="post">
<table>
<tr>
<td>
<span class="pending" style="display:none;">PENDING</span>
<span class="disabled">DISABLED</span>
</td>
<td>
<input type="checkbox" name="statusArray[]" id="change" value="1" />
</td>
</tr>
<tr>
<td>
<span class="pending" style="display:none;">PENDING</span>
<span class="enabled">ENABLED</span>
</td>
<td>
<input type="checkbox" name="statusArray[]" id="change" value="2" />
</td>
</tr>
</table>
</form>
Run codeThe top code works if there is only one line, but I need it to process multiple lines.
The checkbox will always be named statusArray[]and marked as#change
There are 3 spans, although each row will only have two at each point in time, it will span.enabled, span.disabledandspan.pending
jquery toggle ? -, .
.