Cosmetic question:
I have a html element containing possible dimensions for some embedded images, these are stored as:
<div class="inside" data-dimensions='{ "s-x": 213, "s-y": 160, "m-x": ...
I get out the data-dimension and parse with jQuery.parseJSON(jQuery.data(“dimensions”)) all fine and closely following the jquery’s doc.
However I’m used to encapsulate all my html attributes inside double quotes:
<div class="inside" data-dimensions="{ 's-x': 213, 's-y': 160, 'm-x': ...
But then I get a malformed json exception. Are there ways so i can obey my self imposed “double quoted html attributes” law?
You can use
"instead of". But quoting orgies are horrible (in HTML even more than in PHP) so better go with single-quoting your html attributes.BTW, you do not need to use
.parseJSON– jQuery does that automatically if thedata-attribute starts with{(actually, it’s more complex – here’s the regex it uses to test if it should be parsed as JSON:^(?:\{.*\}|\[.*\])$).