What happens when jQuery.data() fails?

I’m still not sure what causes the jQuery .data() function to fail.

EDIT: See edits below.

So when it does fail, I have switched to using .attr(). Yes, you can put “data-something” into your .attr() function call.

I hope to post more information on why .data() function fails. See below

Also note, if the :data selector fails, you can use element[data-something=”somedata”] to get around the issue.

Note: Schema doesn’t change using .data(). and if your call failed to get data then you get ‘Undefined’ object. Sucky object to get.

So now, when I am posting to, or reading from, data- from script, I use .data(), but when reading from data- which was supplied by the browser, I generally use .attr();

I’m not promoting cheating, I just want you to have options.

FTR: Here is the link to the data api.

EDIT:
I went to someone else’ site, who was also talking about .data().
Their example was using jsFiddle, and without messing with the code, just a plain execute, same exact problem. http://blog.mitemitreski.com/2012/06/html-5-data-attributes-how-to-use-it.html
Mite, I think I need to give you a call about the same problem I am seeing. ;)

Note: I know .data() used to work, so I’m not sure what broke it.

EDIT 2:
I was corrected twice on this.

  1. http://www.learningjquery.com/2011/09/using-jquerys-data-apis
  2. http://api.jquery.com/data/#data-html5

Changing a lot of code to accomodate this fix.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.