Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to apply CSS styles in current document recieved from AJAX request?
  2. #id1{something:something}
  3. #id2{something:something}
  4. #id3{something:something}
  5. ...etc ect
  6.        
  7. <link rel="stylesheet" type="text/css" href="..." />
  8.        
  9. var url = "......"; // including parameters
  10.  
  11. var script = $('<link>', {
  12.    rel: 'stylesheet',
  13.    type: 'text/css',
  14.    href: url
  15. }).appendTo(document.head);
  16.        
  17. var data = {id1: {something: something}, id2: {something: something}, id3: {}}
  18.        
  19. $.each(data, function(index, item) {
  20.     $('#' + index).css(item);
  21. });
  22.        
  23. <div id="result"></div>
  24.        
  25. $('head').append('<style> #result { background-color: orange; } </style>');