0

I am in a situation where I need to replace the contents of a <head> element, without replacing the content with what's already there.

My <head> contains the CSS links, the Meta and the title. These are updated from an ajax call, containing the html, which javascript then replaces it with.

My issue is that I get a FOUC because it is also replacing the already loaded CSS, with that CSS. Is there anyway to have it NOT replace the CSS because it's already there?

My code:

var headHTML; // This gets updated on the ajax call
$('head').html(headHTML);
Sebastian Olsen
  • 10,318
  • 9
  • 46
  • 91

1 Answers1

4

While I agree with the comments, and think that there is a better way to do this. here's something you can do to make it work.

Elements inside the <head> can also be selected using jquery. So you can individually change the title and meta like

$('head title').html('your text here');
$('head meta').attr('set it here');
Louie Almeda
  • 5,366
  • 30
  • 38