最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why doesn't the following Javascript code (to set CSS style) work? - Stack Overflow

programmeradmin4浏览0评论

I'm trying to set the CSS style of an object with the following:

document.getElementById(obj).style='font-weight:bold; color:#333;';

but it's not working. Does anyone have any idea why?

I'm trying to set the CSS style of an object with the following:

document.getElementById(obj).style='font-weight:bold; color:#333;';

but it's not working. Does anyone have any idea why?

Share Improve this question edited Jun 29, 2009 at 10:45 paxdiablo 884k241 gold badges1.6k silver badges2k bronze badges asked Jun 29, 2009 at 10:12 ZA.ZA. 10.5k10 gold badges38 silver badges39 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

you can separate

document.getElementById(obj).style.fontWeight='bold';
document.getElementById(obj).style.color='#333';

You need to set the underlying cssText of the style as folows:

document.getElementById('xx').style.cssText='font-weight:bold; color:#333;';

Document's style property is a object, please reference HTML DOM Style Object on W3school

发布评论

评论列表(0)

  1. 暂无评论