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

2019-09-19 12:33发布

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条回答
Ridiculous、
2楼-- · 2019-09-19 12:58

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.

查看更多
登录 后发表回答