jQuery.attr({ map }) + Phonegap iOS 4.x quirk

After trying almost a DAY to figure out why the hell I can’t make the Phonegap’s file API to play nice on iOS 4.x, even if on iOS 5.x everything was just peachy, i tried very last thing i got on my head.

Ok, so I had this snippet of code:

var preview = $('<img />').attr({src : 'data:image/jpeg;base64,' + file, class:'previewImage'})

As I said, everything was ok on iOS 5 (where I initially tested). When I switched to iOS 4, the app crashed (actually all I saw was a blank screen) with no error at all!

[quote]WARNING: When setting the ‘class’ attribute, you must always use quotes![/quote]

After breaking down the code (I had around 400 lines of JS for that file) and trying different versions of Phonegap, I found out that… you kind of need to put attributes inside quotes!

So, after I replaced the above code with:

var preview = $('<img />').attr({"src" : 'data:image/jpeg;base64,' + file, "class":'previewImage'})

I saw the light: everything is working again!

Thank you Apple!

Leave a comment!

You can insert code snippets using BBcode:
[js].[/js] [html].[/html] [php].[/php] [css].[/css]
You can also use some HTML tags:
<blockquote>.</blockquote> <code>.</code> <a href="">.</a> <strong>.</strong> <em>.</em>