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

2 Answers 2

6

You can try this :

<script>
require([
    'jquery'
], function ($) {
    $(".home-banner").insertBefore(".page-main");
});
</script>
4
  • 1
    it's working now so thanks for help @hweb87 May 7, 2018 at 11:52
  • 1
    This also works in CMS Blocks
    – KyleBunga
    Dec 9, 2020 at 21:58
  • Uncaught ReferenceError: require is not defined Jan 30, 2023 at 14:26
  • Share with me your console screenshot Feb 7, 2023 at 11:47
3

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 and acknowledge you have read our privacy policy.

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