I noticed that lots of people put in a space after their email address (autocomplete) i.e. " [email protected] " I use to use this code in M1:

$(':input').change(function() { $(this).val($(this).val().trim()); });

and it was working for all fields.

Is there a way to do this in M2?

1 Answer 1


To use your jQuery in Magento 2.x you can use the below format jQuery code:

Update Code:


<script type="text/javascript">
    require(["jquery"], function(jQuery){
        (function($) {
            $(document).ready(function ($) {


                $(':input').change(function() {


Previous Code:

require([ 'jquery', 'jquery/ui'], function($){

      // put your code here if you want it in document.ready
      $(':input').change(function() { $(this).val($(this).val().trim()); });


       // Your code here
       console.log("bla bla");


 }, 2000);


Hope this will help you to achieve your requirements. Good Luck.

Ref: jQuery not working in checkout page - Magento 2

  • thanks for the reply, but it doesn't work. Not even "bla bla" test Magento 2.4.0
    – Alex I.
    Jan 26, 2021 at 10:05
  • @AlexI.please check the Update Code, it's working on my Magento 2.4.1, hope it will work on your end. Jan 26, 2021 at 13:40

Your Answer

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

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