{"id":12,"date":"2007-10-02T00:42:31","date_gmt":"2007-10-02T06:42:31","guid":{"rendered":"http:\/\/bililite.nfshost.com\/blog\/index.php\/2007\/10\/02\/ajax-style-elements-and-safari\/"},"modified":"2008-08-05T20:06:35","modified_gmt":"2008-08-06T02:06:35","slug":"ajax-style-elements-and-safari","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2007\/10\/02\/ajax-style-elements-and-safari\/","title":{"rendered":"Ajax, Style elements and Safari"},"content":{"rendered":"As I mentioned <a href=\"\/blog\/index.php\/2007\/05\/01\/well-that-is-unfortunate\/\">before<\/a>, I don't have access to a modern version of Safari and when I pass an Apple store, I try to play with it and the site. <em>Something<\/em> always pops up to bite me.\r\nThis time it was an improved version of my Hebrew keyboard, that I made into a popup, absolutely-positioned <code>&lt;div&gt;<\/code> instead of a separate page, using <a href=\"http:\/\/www.alistapart.com\/articles\/sprites\">sprites<\/a> for the keyboard button rollovers. Nice and elegant, but it means loading the <code>&lt;style&gt;<\/code> element with all those <code>a:hover {background: 0 -150px}<\/code>'s via Ajax as well. Just putting a <code>&lt;style&gt;<\/code> element in the loaded <code>&lt;div&gt;<\/code> worked fine in IE and Firefox, but today Safari wouldn't show any styles. Turns out Safari is technically right;  <code>&lt;style&gt;<\/code>'s go in the <code>&lt;head&gt;<\/code>, not the middle of the <code>&lt;body&gt;<\/code>. That's a rule that doesn't make any sense, any more than requiring <code>&lt;script&gt;<\/code> elements to be limited to the <code>&lt;head&gt;<\/code> would. But such are the rules.\r\n\r\nI looked up a <a href=\"http:\/\/www.phpied.com\/dynamic-script-and-style-elements-in-ie\/\">few<\/a> <a href=\"http:\/\/dev.rubyonrails.org\/ticket\/8282\">ways<\/a> to include a <code>&lt;style&gt;<\/code> element, but realized there's an easier way; I split the style into its own stylesheet and added a line to Javascript:\r\n<code>$('head').append('&lt;link type=\"text\/css\" href=\"\/css\/kb.css\" rel=\"stylesheet\" &gt;');<\/code>\r\nbefore the\r\n<code>$('&lt;div id=\"keyboard-holder\"&gt;').insertAfter('#q').load('\/inc\/keyboard.html'); \/\/ load via Ajax<\/code>\r\nand now the style loads dynamically and easily.\r\nLuckily, jQuery handles identifying and executing <code>&lt;script&gt;<\/code> elements in Ajax'ed code, so I don't have to pull that out.","protected":false},"excerpt":{"rendered":"As I mentioned before, I don't have access to a modern version of Safari and when I pass an Apple store, I try to play with it and the site. Something always pops up to bite me. This time it was an improved version of my Hebrew keyboard, that I made into a popup, absolutely-positioned [&hellip;]","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/12"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":1,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions\/41"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}