One of the challenges I am facing is trying to toggle a text box on a checkbox's click event. While I have achieved success in this aspect, my issue lies in changing the checkbox's required attribute as well.
Below is the code that successfully removes the required attribute but fails to toggle it:
$('#sender_name').change(function(event){
if ($('#sender_name').attr('required', 'required'))
{
$('#sender_name').removeAttr('required', 'required');
}
else
{
$('#sender_name').attr('required', 'required');
}
$('.sender_name_text').toggle();
});
Upon using this code, the checkbox's attribute gets removed, however, it does not get applied again. You can verify this by checking the Fiddle through inspecting elements.
Here Is Fiddle Link
-- Regards