It's more simple:
$('input[name=accountType]').change(function(){
$('#facebook').toggle(this.value !== '1');
});
Demo. First, change
event is fired on the radio button that's checked, so there's no need to look for it with the full selector again - this
would refer to the corresponding element, and this.value
will give you its value.
Second, there's a convenient .toggle
jQuery method that can be used to show or hide the element depending on some condition (show if it's truthy, hide if falsy). In this case, you need to hide the element if this.value
is equal to '1', that's why I reverse the check (with !==
).
As a sidenote, I've removed the quotation marks around 'accountType' - these are not required if attribute value (in attribute selector) is a valid JS identifier.