简体   繁体   中英

Parent and child event listener

I am creating a web page that uses bootstrap, jquery and inspinia template.

I use 3 files namely index.html - Where I import all my scripts

<body ng-controller="MainCtrl" class="">

    <div id="wrapper">
        <div ng-include="'/app/components/navigation/navigation.html'"></div>
        <div ng-include="'/app/components/header and footer/headerFooter.html'"></div>
    </div>
</body>

<!-- JS -->
<script type="text/javascript" src="./assets/node_modules/jquery/dist/jquery.js"></script>
<script src="./assets/js/inspinia.js"></script>

<script type="text/javascript" src="./assets/node_modules/angular/angular.js"></script>
<script type="text/javascript" src="./assets/node_modules/bootstrap/dist/js/bootstrap.js"></script>

navigation.html - Where my side bar is in place headerFooter.html - Where the button for sidebar toggle is place

inspinia.js - where the event listener is place

$('.navbar-minimalize').on("click", function (event) {
    $("body").toggleClass("mini-navbar");
    SmoothlyMenu();

});

The question is, Why does whenever I press the button the side-bar doesn't turn into mini-navbar (class not applying) is this kind of setup.

but if all the div element is in index and not using ng-include the button is toggling properly.

BTW: I am using bootstrap 3.xx

Change:

$('.navbar-minimalize').on('click, function() {});

to:

$('body').on('click', '.navbar-minimalize', function() {});

Angular insert your HTML at runtime, so your jQuery code doesn't know about your DOM on start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM