Style=“display:block;” works in Chrome but not Safari

邮差的信 提交于 2019-12-13 10:33:13

问题


I have a banner on my website that by default is not shown. The code I am using to get it to show is

document.getElementById("cookie1").style = "display:block;"

This works in Chrome but is not working in safari. I am not getting any errors in Safari either, It just doesn't show the banner.

Any ideas on what could be causing this? Or a better way to hide/show a page element?

Thanks!


回答1:


From testing this in Chrome and Safari, it seems Chrome is more forgiving in that it parses the style string and puts the right style in place for you, but Safari does not.

Try:

document.getElementById("cookie1").style.display = 'block';

It's probably best to be explicit like that anyway, instead of relying on string parsing for the style itself.



来源:https://stackoverflow.com/questions/41959814/style-displayblock-works-in-chrome-but-not-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!