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

I'm trying to set the CSS style of an object with the following:document.getElementById(obj).style

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744845375a4596802.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信