1

I'm trying to add multiple jQuery data entries to a single element.

I suspected that the following would work

jQuery('td.person#a'+personId).data('email',thisPerson.email).data('phone',thisPerson.phone);

However, I am getting nothing but errors when I do this.

jQuery('td.person#a'+personId).data('email',thisPerson.email);
jQuery('td.person#a'+personId).data('phone',thisPerson.phone);

is there another way to get more than one data entry on an element? Hopefully chained?

4

1 回答 1

9

You can pass an object into .data(), like this (broken so to prevent horizontal scroll)

jQuery('td.person#a'+personId)
      .data({email:thisPerson.email, phone:thisPerson.phone});

To answer your question though, yes it should be chainable, if you post what errors you were getting that would help see why it isn't working.

于 2010-04-19T17:41:50.757 回答