Control Freak
Control Freak

Reputation: 13243

Browser compatible work-around instead of using .data()

Seems like certain browsers (Internet Explorer with Compatibility View ON) don't support the .data() object, whats the next best thing to use?

$("#object").data('value','hi');

I was thinking I could apply classes to the object and use hasClass() but maybe there's a better way? Would be better if it was as lightweight as possible (without using cookies)

Upvotes: 1

Views: 92

Answers (2)

Dharman
Dharman

Reputation: 33393

You can use html5 data attributes.

$("#object").attr('data-val1','hi');

Upvotes: 1

Matti Virkkunen
Matti Virkkunen

Reputation: 65156

I'm fairly certain data() works even in that mode.

If it doesn't, add the correct meta tags into your <head> to force IE not to use broken mode.

Upvotes: 2

Related Questions