So, I get the data through the jquery ajax method. The data obtained are as follows:
<html> <head> <style> body { color: red; font-weight: bold; } #someElement { color: blue; padding: 1em } </style> </head> <body> <div id="header">Super</div> <p>blah blah blah</p> <div id="footer">Stuff</div> </body> </html>
How to extract a style and paste it into the current document that is making an ajax call? I tried all kinds of jquery spells, but it is not. I am now extracting css via regex, but I'm not sure how to put css in the current page:
$.ajax({ url: '/template.html', success: function(data) { $("#header").html( $(data).find('#header').html() ); $("#footer").html( $(data).find('#footer').html() ); var re = /<style>((?:[\n\r]|.)+)<\/style>/m; var css = re.exec(data);
First I had a stylesheet, and then the following was simply done:
if($.browser.msie) { $('head').html( '<link rel="stylesheet" href="http://c.this/template.css" type="text/css" />'+ $('head').html() ); } else { $('head').prepend('<link rel="stylesheet" href="http://c.this/template.css" type="text/css" />'); }
This works, with the exception of IE8, it causes some problems.
PaulS
source share