0

What is wrong with these jQuery data() assignments? When I wrap the first in a console.log(), it works and prints out the data.

But jsbin shows tons of errors that I can't put my finger on?

$("body").data("user_information", {});
$("body").data("user_information", {
    contact_info: {},
    billing_info: {}
});

console.log($("body").data("user_information").contact_info, {name: "paul", company: "testCo"});

$("body").data("user_information").contact_info, {
    name: "paul",
    company: "testCo"
};

$("body").data("user_information").billing_info, {
    name: "steve",
    company: "testCo"
};

jsbin

Alexander
  • 23,432
  • 11
  • 63
  • 73
1252748
  • 14,597
  • 32
  • 109
  • 229
  • After the `console.log`, you have syntax errors and it's very clear in JSBin. Can you tell us what are you trying to do in the fourth and fifth lines? – Alexander Feb 26 '13 at 16:40
  • @Alexander in `contact_info: {}, billing_info: {}` I'm trying to set up `contact_info` and `billing info` as empty objects. I'm sorry, the errors are not that clear to me. Can you explain? Thank you. – 1252748 Feb 26 '13 at 16:45

1 Answers1

2

If you're trying to do assignment, you should do it like this:

$("body").data("user_information").contact_info = {
    name: "paul",
    company: "testCo"
};

The comma operator you were using there was confusing me. Alternatively, you could do

$("body").data("user_information", {
        contact_info: {
            name: "paul",
            company: "testCo"
        }
});
MrLeap
  • 506
  • 2
  • 11