1

So what I'm trying to do is to show currently hidden custom field when a certain option from the dropdown menu is selected but can't seem to achieve this. Or in other words, after clicking on the specific option I would like to change the CSS on the currently hidden field from display:none to display:block.

I've managed to achieve that the custom field displays after clicking anywhere on the select menu with the code below, but this isn't enough. The hidden field should display only if you choose a specific option.

So this works...

jQuery('#select-menu').click(function() {
  jQuery('.custom-field-wrapper').css('display', 'block');
});

But this doesn't...

jQuery('#select-menu option:last').click(function() {
  jQuery('.custom-field-wrapper').css('display', 'block');
});

Any idea what I'm doing wrong and how to fix or workaround this?

1

1 Answer 1

1

You can't add click event listener to option, instead you have to check value of select and react accordingly: Something like this should work:

jQuery('#select-menu').on('click change', function() {
  if ($(this).val() === 'targetValue') {
    jQuery('.custom-field-wrapper').css('display', 'block');
  } else {
    jQuery('.custom-field-wrapper').css('display', 'none');
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.