SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing object using a variable

    Hi, 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:

    HTML 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 .cc 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.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    The jQuery data() method might be a useful way for you to store and retrieve objects.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •