Jon Jon - 1 year ago 254
Javascript Question

Jquery is returning prevObject in module

Im using browserify and splitting my code into modules like this article.

I have run into a problem below where

is not returning the
jQuery object $('.burger')
instead it is returning "prevObject" . Am I missing something here?

any help is appreciated.

'use strict';

var s,
toggleNavigation = {

settings: {
button: $('.burger'),
active: 'is-active'

init: function() {
s = this.settings;

bind: function() {
s.button.on("click", function() {



module.exports = toggleNavigation

Answer Source

Probably at the time $('.burger') runs the element doesn't exist yet (not run on document load), so you don't see anything but the prevObject field.

The prevObject field is used for chaining jQuery selectors. It would hold a reference to another DOM element if you would to use something to narrow down the selection, for example: .filter().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download