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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:51:27+00:00 2026-05-22T01:51:27+00:00

I have an object whose name is mural. I have assigned the name mural

  • 0

I have an object whose name is mural. I have assigned the name mural to the title of an anchor element. When user clicks and element I want to store the title of the anchor in a variable called sprite. I then want to access that object whose name corresponds to the sprite variable string.

Here is my code:

var mural= new Object();
mural.top='0px';
mural.left=-'510px';

var stamps= new Object();
stamps.top='0px';
stamps.left=-'1886px';

var sprite=$(this).attr('title');

$(".image-holder").css("background-position",'sprite.top, sprite.left');

It’s not working because the the variable sprite is just a reference to $(this).attr(‘title’), how do I make it reference the object?

Oh and I know that .css jquery statement probably wont work, I’m not sure yet of the correct way to have two values that don’t need quotations in as the second argument. But I am mainly concerned with the way to get access to the object.

  • 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-22T01:51:28+00:00Added an answer on May 22, 2026 at 1:51 am

    Use bracket notation, e.g. if stamps and mural are global objects:

    var sprite = window[$(this).attr('title')];
    

    JavaScript does not parse strings for variable substitution, you have to use string concatenation as the others already showed:

    .css("background-position", sprite.top + ' ' + sprite.left);
    

    But depending on the context, maybe it is possible to just use CSS:

    .mural {
         background-position: 0px 510px;
    }
    
    .stamps {
         background-position: 0px 1886px;
    }
    

    JS

    $('a').click(function() {
        $(".image-holder").addClass($(this).attr('title'));
    });
    

    If this is not possible, I would actually store both sprites in a map:

    // in some higher scope
    var sprites = {
        mural: {
            top: '0px',
            left: '510px'
        },
        stamps: {
            top: '0px',
            left: '1886px'
        }
    };
    
    // in your event handler
    var sprite = sprites[$(this).attr('title')];
    

    But without knowing more about the context it is difficult to give a better suggestion.

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

Sidebar

Related Questions

i have a button in gridview whose command name is hold i want when
I have a custom object whose structure is public String name; public int type;
Lets say that you have a business object whose current state implies that there
Suppose I have a UserControl whose DataContext is set to an object that has
I have a Tags table whose schema consists of only ID and Name (unique).
I have a multiview on my ASPX page whose ActiveViewIndex I want to set
I'm using Spring 3 and JSR 303. I have a form backing object whose
I have an AS3 Object: {p1:.., p2:..} I want con create another object that
I have an ItemsControl whose for the ItemTemplate DataTemplate contains a Button. I want
Assume I have a business object like this, class Employee { public string name;

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.