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

  • Home
  • SEARCH
  • 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 8049205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:43:32+00:00 2026-06-05T06:43:32+00:00

I have a javascript class like this (i know it’s technically not a class).

  • 0

I have a javascript class like this (i know it’s technically not a class).

function StackMedia (container) {

    this.container = container;
    this.items = container.find('.stackItem');
    console.log("this.items.length: "+this.items.length);

}

I pass a container (div) that holds other divs with the css class stackItem, those get stored in items.

Here i want to reuse it:

StackMedia.prototype.updatePositions = function() {

     for (var i = 0; i < this.items.length; i++) {
         this.items[i].css('left', 50);
    }
}

The problem is that it isn’t a jquery object anymore so i get this error:

TypeError: ‘undefined’ is not a function (evaluating ‘this.items[i].css(‘left’, 50)’)

How can i store them as a jquery object?


update

Here is where i create the classes (works fine):

// create a stack by passing a container
    $('.stackContainer').each(function(containerIndex) {
        $(this).css('z-index', containerIndex);
        stacks.push(new StackMedia($(this)));
    });

This is almost fine apart from the last line

StackMedia.prototype.updatePositions = function() {

    var sm = this; // StackMedia

    // set the css properties of the items
    this.items.each(function(i){
        $(this).css('left', sm.x + i * sm.overlapX);
        $(this).css('top', sm.y + i * sm.overlapY);
        $(this).css('width', sm.itemWidth);
        $(this).css('height', sm.itemHeight);
        $(this).find('img').css('width', sm.itemWidth);
        $(this).find('img').css('height', sm.itemHeight);
    });

    // set the css properties of the container
    //console.log(sm);
    console.log($(this));
    $(this).container.css('width', 400);

};

I get this again: TypeError: ‘undefined’ is not an object (evaluating ‘$(this).container.css’)

So $(this).container lost it’s jquery functionality, how can i get it back?

  • 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-06-05T06:43:33+00:00Added an answer on June 5, 2026 at 6:43 am

    this.items is a jQuery object. Don’t loop over it using a normal for loop, use jQuery’s .each.

    this.items.each(function(){
        $(this).css('left', 50);
    });
    

    I’m pretty sure .css affects all elements in a jQuery object, so you can just do:

    this.items.css('left', 50);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a class in JavaScript with a single method: function MyClass(text) {
I have in my javascript these 2 functions classes: // product class function Product()
I have a class for DIVs called .post and I'd like to find words
I have some javascript that goes out and fetches a javascript class on another
I have the following javascript class which I am trying to pass to an
I have a class within Javascript with a variable assigned in the constructor. I
I have the below code to create a class in javascript.... Now i will
I'm trying a more object oriented approach with javascript and have implemented a class
I have a class that stores paths to CSS and Javascript files in arrays.
I have a span that is generated through javascript, with its css class as

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.