$(document).ready(function() {
var $profile = $('#edit-profile-country'),
$state = $('#state'),
$province = $('#province');
function toggleStateProvince() {
var val = $profile.val();
$province.hide();
$state.hide();
if (val == 'US') {
$state.show();
} else if (val == 'CA') {
$province.show();
}
}
toggleStateProvince();
$profile.change(toggleStateProvince);
});
As for checking for the existence of an element, there's two things to
keep in mind:
1) You can check the length of the jQuery object to see if it found
any elements: if ($('#state').length) { ... }
2) If you don't care what happens if the element doesn't exist,
there's no need to check for it: $('#state').show() just won't do
anything if #state doesn't exist (no errors).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---