admin管理员组文章数量:1302409
In this simple example / why is the #test
element not being shown before the alert appears?
Shouldn't the jQuery css()
method be syncronous?
#test {
display: none;
}
<span id="test">Element</span>
$("#test").css("display", "inline");
alert("Showed element!");
UPDATE:
This behavior is manifesting for me on Chrome Version 52.0.2743.116 m, Windows 10.
In this simple example https://jsfiddle/4rsje4b6/1/ why is the #test
element not being shown before the alert appears?
Shouldn't the jQuery css()
method be syncronous?
#test {
display: none;
}
<span id="test">Element</span>
$("#test").css("display", "inline");
alert("Showed element!");
UPDATE:
This behavior is manifesting for me on Chrome Version 52.0.2743.116 m, Windows 10.
Share edited Aug 16, 2016 at 13:19 Legionar 7,6073 gold badges44 silver badges71 bronze badges asked Aug 15, 2016 at 17:42 Andrea CasacciaAndrea Casaccia 4,9714 gold badges33 silver badges55 bronze badges 3- Well, it seems to work for me (Firefox 47.0.1 on Windows 7). Can't send you a screenshot right now but I can clearly see the "Element" word rendered on the DOM while the alert is shown. – Roberto Linares Commented Aug 15, 2016 at 17:46
- Yep works for me too in Firefox 47.0.1, behavior has been observed on Chrome Version 52.0.2743.116 m. – Andrea Casaccia Commented Aug 15, 2016 at 17:49
- Same Issue I am facing too. Someone can help that how can use or fixed it for Chrome Browser? here is the example narendra-pal-singh.github.io/Web-Development/html/divBox.html – npsingh Commented Feb 23, 2020 at 13:29
1 Answer
Reset to default 13It changes the style synchronously, and you will notice that if you read back the value on the next line and show it.
$("#test").css("display", "inline");
alert("Showed element!" + $("#test").css("display"));
But the change of the style object triggers a repaint request message to the page renderer, and that is handled as soon as the browser bees idle, which is after this script routine has ended.
It depends on the browser, though. In Edge it works fine, and the element is shown right away but in Chrome and Vivaldi it is not.
Another test to see how browsers handle this: If you resize the browser window, JSFiddle will scale (each of the areas keeps the same relative size). If you resize the Vivaldi browser with the alert open, it doesn't do that. In fact if you make it small, then show the alert, then make it larger, you just get a grey area in the new space until you close the message box. In Edge, the fiddle will just resize in the background, even though the entire browser window is grayed out, so it's not just a matter of the time of processing, but more that Chrome pletely freezes the page when an alert is open.
本文标签: javascriptWhy is element not being shown before alertStack Overflow
版权声明:本文标题:javascript - Why is element not being shown before alert? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741665366a2391278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论