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 8022659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:19:41+00:00 2026-06-04T22:19:41+00:00

In a javascript program there is an array (gData) that contains objects. Each of

  • 0

In a javascript program there is an array (gData) that contains objects.
Each of these objects has a property called label that is an object.
each label contains a span called span_ within a div called div_.

Amongst other gData related operations, the label object is instantiated as

gData.label = new Label();

and then the gData object is pushed onto the gData array.

In the main program, i can execute the following jquery code that works fine:

$(gData[0].label.span_).css("border","5px solid green");

I want to add a function prototype to the label object called setCSS(). I would call the setCSS method like this:

gData[0].label.setCSS("border","5px solid green");

The setCSS code that I wrote (below) does not work. I’m guessing that the selector isn’t working.

Label.prototype.setCSS = function(args) {

// args contains an object in the form {"cssAtribute":"cssData"}
// call this method as label.setCSS({"border":"3px solid blue"});
// Any number of css attributes can be included in the args object

    $.each(args, function(theKey, theValue) {
        $(this.span_).css(theKey, theValue);
    });
}

I’ve tried $(this.span_), $(this.div.span_) and several other selectors, none work.

Using Firebug I can see that gData[0] contains a label object and the label object contains a span_ object. Is my selector specification wrong? or have I missed some other cause that will make me feel dumb?

  • 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-04T22:19:44+00:00Added an answer on June 4, 2026 at 10:19 pm

    this inside a jQuery.each will have a different scope. You need to save it first in a local variable:

    var $span = $(this.span_);
    $.each(args, function(theKey, theValue) {
        $span.css(theKey, theValue);
    });
    

    Note that you example .setCSS("border","5px solid green"); will not work using this method, as it requires the argument to be an object using key/values.

    However, you should be able to simplify the method to:

    Label.prototype.setCSS = function() {
        $.prototype.css.apply($(this.span_), $.makeArray(arguments));
    };
    

    That way you can use it the same way jQuery uses .css() including your implementation example.

    Fiddles:

    First example: http://jsfiddle.net/ESrSY

    Second example: http://jsfiddle.net/UpEPK

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

Sidebar

Related Questions

is there a way to write a program in php or javascript that can
I'm converting a Javascript program I wrote into Java, and there's one Object which
I am writing a javaScript program that has N number of Div's and when
HI, I have a JavaScript program that's written with object literal syntax: var MyJsProgram
I'm writing a small JavaScript program that makes web calls to pull up weather
I am working on a php program that requires javascript on every form control.
I'm trying to add a menu to my Javascript program that will allow a
When I console.log() an object in my JavaScript program, I just see the output
Is there a way to change the root object in JavaScript? For example, in
I'm working on a program that uses HTML/CSS/Javascript/JQuery for its user interface. One of

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.