1

how to add cms home page jquery in magento 2

jQuery(document).ready(function($){

   $(".home-banner").insertBefore(".page-main");

 });

Please advance thanks for help

5

You can try this :

<script>
require([
    'jquery'
], function ($) {
    $(".home-banner").insertBefore(".page-main");
});
</script>
2
  • 1
    it's working now so thanks for help @hweb87 – Ravindrasinh Zala May 7 '18 at 11:52
  • 1
    This also works in CMS Blocks – KyleBunga Dec 9 '20 at 21:58
1

You can also use domReady! so that it only loads if the DOM is ready:

<script>
    require([
        'jquery'
        ,'domReady!'
    ], function ($) {
        $(".home-banner").insertBefore(".page-main");
    });
</script>

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.