Happy
Happy

Reputation: 891

jQuery without domready

Searching for a way to add this code, after the <head> (or some <link stylesheet>) and before <body> is generated (created).

$('body').append('<style type="text/css">\
    // some
    // multiline
    // styles
</style>');

There is no <body> without domready(), so its seems better to use head instead or something else. Append also can be replaced.

There is no direct access for html file edit, thats why I'm using javascript.

Why is it needed? When we use domready() script adds styles after the page is generated, so blocks with new styles jumps from previous decoration to new - not good, thats why we should use another hook.

Anybody knows how to do that?

Thanks.

Upvotes: 0

Views: 307

Answers (2)

ScottE
ScottE

Reputation: 21630

Did you try $('body').prepend() or $('head').append() ? You need the DOM to be ready before you can inject html using jquery, so I think you're stuck with document ready.

Upvotes: 0

Anurag
Anurag

Reputation: 141899

<script type="text/javascript">
document.write('<style type="text/css">\
    // some
    // multiline
    // styles
</style>');
</script>

Place it wherever you want.

Edit: I don't think what you want is possible, but I'd love to be proven wrong. You don't have any hooks into the DOM parsing stage. And once the DOM is constructed, it's already too late by then for your purposes.

Upvotes: 2

Related Questions