Monaca Onsen UI Discord Chat Github Repo

jQuery selector not working for

  • Hi
    Trying to close ‘Spliter side’ with button click.

    <ons-splitter-side id="menu" side="left" width="120px" animation='push' collapse  swipeable>

    This works:

    var menu = document.getElementById('menu');

    This does not work:


    I get error "Uncaught TypeError: menu.close is not a function"
    Other jquery commands are working.
    What could be the reason?

  • Onsen UI

    @Zeni close is a method of the element itself, not of the jQuery wrapper. Try $('#menu')[0].close();.

  • @Fran-Diox

    Thanks Fran, it solved my problem. You are Guru!!.

  • Uncaught TypeError is usually caused because scripts are loaded in the wrong order . The browser will execute the scripts in the order it finds them. If in a script you attempt to access an element that hasn’t been reached yet then you will get an error. Make sure that you don’t have a script above one that it requires.

    Sometimes this warning may also be shown if jQuery is declared more than once in your code. The second jQuery declaration prevents bootstrap.js from working correctly. The problem is due to having jQuery instances more than one time. Take care if you are using many files with multiples instance of jQuery. Just leave one instance of jQuery and your code will work.