开发者

jQuery without domready

开发者 https://www.devze.com 2023-01-04 00:25 出处:网络
Searching for a way to add this code, after the <head> (or some <link stylesheet>) and before <body> is generated (created).

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?

Tha开发者_JAVA技巧nks.


<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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消