How to Use jQuery Library in Magento 2?

  • author-img Nidhi Arora
  • 8 years
How to Use jQuery Library in Magento 2-

Magento 2 comes with a lot of built-in by-default features. Although, there is always a need to include jQuery while creating a Magento 2 theme as it facilitates a dynamic & interactive front-end. Require JS enhances performance by enabling javascript to get loaded in the background similar to Lazy javascript loading.

To add jQuery library in Magento 2, you need to include the jQuery code inside require:

<script type=”text/javascript”>

 

    require([‘jquery’],function($ ){

 

  $(document).ready(function(){

 

   alert(“hello”);

 

        });

 

    });

 

</script>

It is the most recommended way and the best practice to use jQuery library in Magento 2. Share your feedback & queries and also let us know if you need any assistance along the way.

Download Blog

ENQUIRY

Ready to Get Started

Communication is the key for us to understand each other. Allow us to understand
your requirements or queries. Present us with an opportunity to serve you.

Fill out the form and out team will get back to you
within 24 hours

    Head Office

    815 Brazos St STE 500, Austin,
    TX 78701, USA