简体   繁体   中英

How can I set a CSS property on the html element with jQuery?

How can I set a CSS property on the html element with jQuery?

I'm trying to do something like...

$('html').css({'background': 'url(/images/bg.png) top center'})

EDIT: For those that will ask why not just set it on the body or some other work around, this needs to be set like this as it fixes a webkit bug in iOS 4

EDIT 2: I guess this is doing what it should already. It must be something with the finicky bug that is causing this to act differently then when I set it via external CSS, strange

就像这样:

$('html').css('background', 'url(/images/bg.png) top center')

There's nothing syntactically incorrect about your jQuery code.

EDIT: Try setting it to the body and the html:

$('html, body').css({'background': 'url(/images/bg.png) top center'})

If you're only doing one change, it's best to use the singular form:

$('html, body').css('background', 'url(/images/bg.png) top center')

Try the following

$('theSelector').css('background', 'url(/images/bg.png) top center');

For the theSelector portion you can use the most appropriate jQuery selector for your situation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM