开发者

How to reference background image via DOM

I know I'm doing something wrong here:

document.getElementById("body_bg_top").style.background-image:url(main_bg_开发者_如何学编程top.jpg);

If anyone can correct me I would appreciate it, thank you!


background-image has no hyphen, so just

document.getElementById("body_bg_top").style.backgroundImage="url(main_bg_top.jpg)";

Also need to replace the colon with an equals and wrap the url() in quotes.

http://www.w3schools.com/jsref/prop_style_backgroundimage.asp


With jQuery, you can use:

$('#element-name').css('background-image');

to access that particular CSS property.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜