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
Ravindrasinh Zala
2,1573 gold badges17 silver badges49 bronze badges
-
which custom js you are using here? I can see only jquery.Rizwan Khan– Rizwan Khan2020年09月29日 04:25:55 +00:00Commented Sep 29, 2020 at 4:25
1 Answer 1
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
Rizwan Khan
1,9692 gold badges20 silver badges43 bronze badges
default