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

Javascript won't overwrite CSS display property - Stack Overflow

programmeradmin1浏览0评论

I have a DIV that is set do display:none from CSS and it's supposed to be made visible (style.display = '';) at some point by javascript.

The problem is that if I put the display:none in the CSS file the javascript does not seem to have any effect. I have also tried changing the background color instead of the display property, and that works.

I have the code running here (just press the edit link).

I really thank you for taking the time to look into this.

I have a DIV that is set do display:none from CSS and it's supposed to be made visible (style.display = '';) at some point by javascript.

The problem is that if I put the display:none in the CSS file the javascript does not seem to have any effect. I have also tried changing the background color instead of the display property, and that works.

I have the code running here (just press the edit link).

I really thank you for taking the time to look into this.

Share Improve this question edited Jan 1, 2011 at 23:46 jball 25k9 gold badges72 silver badges92 bronze badges asked Jan 1, 2011 at 23:33 Sorin ButurugeanuSorin Buturugeanu 1,1227 gold badges13 silver badges19 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Set it to block or inline using Javascript.

Writing style.display = "" will clear any display set in the inline style, and cause it to revert to whatever it inherited from CSS.

Alternatively, you can change the element's className using Javascript so that the CSS rule no longer applies.

This is because style.display = '' only affects inline styles on an element. It doesn't change the style sheet.

You should set it to whatever display you need:

style.display = 'block';

or add a class that represents the style you want.

other way to hide content is use opacity=0 and to again make visible use opacity=1 thats it....!!!

发布评论

评论列表(0)

  1. 暂无评论