Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:48:07+00:00 2026-05-25T15:48:07+00:00

I have a javascript object as such (simplified). var MyObject = (function(){ var propertyOne

  • 0

I have a javascript object as such (simplified).

var MyObject = (function(){

  var propertyOne = $('.links li:first-child');
  var propertyTwo = $('.links .active');

  function startup()
  {
    propertyOne.addClass("class");  //Works
    propertyTwo.addClass("class2");  //Does not work
    $('.links .active').addClass("class2");  // Works
  }

  return {
     init: function()
     {
       startup();
     }
  }
});

What’s the difference in the way I’m selecting propertyOne and propertyTwo? I don’t understand why

propertyOne.addClass("class");  //Works
$('.links .active').addClass("class2");  // Works

Yet…

propertyTwo.addClass("class2");  //Does not work

Can anyone help explain this to me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:48:08+00:00Added an answer on May 25, 2026 at 3:48 pm

    The DOM element for propertyTwo must not exist at the time that var propertyTwo = $('.links .active') is called, whereas it does once startup() is called.

    To confirm this, we’ll need more information about your script. For example, what I previously described could occur if MyObject is created prior to the DOM being fully loaded, and then you call the init() method after the DOM is fully loaded (or at least after the element corresponding to $('.links .active') has been loaded.

    Regardless, you should really focus on learning how to debug something like this along with why this specific attempt is not working. The main step in this process is to log to the console propertyTwo right after the line var propertyTwo = $('.links .active'). If the console shows [] (in Chrome at least), that means no elements were matched, which would support what I said is happening.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a JavaScript object such as: var list = { you: 100,
If I have a JavaScript object such as: var x = {foo: 42, bar:
If I have a javascript object/assoc. array defined like this: function somefunction(options) { var
I have a javascript that does this (http is your XMLHttpRequest object) var r
I currently have a Javascript function that uses a string to reference an object
I'd like to have JavaScript objects within another JavaScript object as such: Issues: -
i have JavaScript components, that has following architecture: var MyComponent = function(params) { setup(params);
ok i have a javascript object to control elements on my page such as
I have a Javascript object that requires 2 calls out to an external server
I have a Javascript object that basically represents a Row in an .NET GridView.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.