0

How to use custom js in Magento 2.3 add jquery

jQuery('.customdrop select').on('change',function(){
    console.log(jQuery('.customdrop select').find(":selected").text));
    if (jQuery('.customdrop select').find(":selected").text() === 'Other'){
        jQuery('.customfields').show();
    } else {
        jQuery('.customfields').hide();
    }
});
1
  • which custom js you are using here? I can see only jquery. Sep 29 '20 at 4:25
0

You can use JQuery using requirejs as below.

require(['jquery'], function ($) {
    $('.customdrop select').on('change',function(){
        console.log($('.customdrop select').find(":selected").text));
        if ($('.customdrop select').find(":selected").text()==='Other'){
            $('.customfields').show();
        } else {
            $('.customfields').hide();
        }
    });        
});

You can include the above code in your phtml file or in your custom js and include it using layouts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.