jquery - On click, hide div and remove required attribute -



jquery - On click, hide div and remove required attribute -

i have form can appear on different pages, , depending on circumstance, fields not required.

i have code hide div, need input fields no longer required. using html5 required attribute. having problem getting code work. code below:

$('#detailssame').click(function() { if($(this).is(':checked')) { $(\"#detailssamehide\").hide(); } else { $(\"#detailssamehide\").show(); } }); $('.fullboxform input[type=text], .fullboxform select').each(function() { $(this).removeattr('required'); });

all help appreciated.

turns out above code work correctly, alternative reply available using prop

try utilize prop() function setting html5 properties.

$(function () { $('#detailssame').click(function() { var checked = $(this).is(':checked'); if(checked) { $("#detailssamehide").hide(); } else { $("#detailssamehide").show(); } $('.fullboxform input[type=text], .fullboxform select').each(function() { $(this).prop('required', !checked); }); }); });

http://jsfiddle.net/thsxu/

jquery html5 input attributes

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

How do you set up a perforce server to work over the internet? -

ios - Lagging ScrollView with UIWebview inside -