<td>
<input id="check" type="checkbox" name="del_attachment_id[]" value="<?php echo $attachment['link'];?>">
</td>
<td id="delete" hidden="true">
the file will be deleted from the newsletter
</td>
I want to know how can i change the attribute "hidden" to false in Jquery when the checkbox is checked or not checked.
This question is related to
javascript
jquery
A. Wolff was leading you in the right direction. There are several attributes where you should not be setting a string value. You must toggle it with a boolean true
or false
.
.attr("hidden", false)
will remove the attribute the same as using .removeAttr("hidden")
.
.attr("hidden", "false")
is incorrect and the tag remains hidden.
You should not be setting hidden
, checked
, selected
, or several others to any string value to toggle it.
$(':checkbox').change(function(){
$('#delete').removeAttr('hidden');
});
Note, thanks to tip by A.Wolff
, you should use removeAttr
instead of setting to false. When set to false, the element will still be hidden. Therefore, removing is more effective.
You can use jquery attr method
$("#delete").attr("hidden",true);
Use prop()
for updating the hidden property, and change()
for handling the change event.
$('#check').change(function() {_x000D_
$("#delete").prop("hidden", !this.checked);_x000D_
})
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>_x000D_
<table>_x000D_
<tr>_x000D_
<td>_x000D_
<input id="check" type="checkbox" name="del_attachment_id[]" value="<?php echo $attachment['link'];?>">_x000D_
</td>_x000D_
_x000D_
<td id="delete" hidden="true">_x000D_
the file will be deleted from the newsletter_x000D_
</td>_x000D_
</tr>_x000D_
</table>
_x000D_
Source: Stackoverflow.com