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();
 }
});
asked Sep 29, 2020 at 2:59
1
  • which custom js you are using here? I can see only jquery. Commented Sep 29, 2020 at 4:25

1 Answer 1

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.

answered Sep 29, 2020 at 4:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.