0

Can I hold jquery objects as a key of javascript object somehow? (edited).. as a key..

var $a = $("#a");
var $b = $("#b");

var c = {};

c[$a] = foo;
c[$b] = bar;
1
  • Hey, you've changed the question! I've appended more info to my answer. Commented Nov 21, 2013 at 10:52

1 Answer 1

4

Yes, you can. jQuery objects are JavaScript objects.

var $a = $("#a");
var $b = $("#b");

var c = {};

c.foo = $a;
c.bar = $b;

As a key? No, you can't.

A JavaScript object is a mapping between keys and values. Keys are strings and values can be anything.

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Objects

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.