is there any event jquery or javascript where can i hide elements before they appears in browser

蓝咒 提交于 2019-12-12 01:46:11

问题


Now i have onready event handler

$(function() {
   $('element').hide();
});

but element is hiding only after it appears in browser. And it disappear like a flash.

Can i bind any hide() function before content appears in my browser ?


回答1:


Can i bind any hide() function before content appears in my browser ?

No. The DOM must be loaded first before being able to manipulate it with javascript. The best way is to simply hide the element using CSS from the server side so that it never shows when the page loads. So define a hidden class in your CSS file:

.hidden {
    display: none;
}

and then apply it to your element:

<div class="hidden">some hidden content</div>



回答2:


Is there a reason why you couldn't apply a class like this to your element

HTML

<div class="s-hidden">Hello foo!</div>

CSS

.s-hidden { display: none; visibility: hidden; }

Note that visibility:hidden also hides the element from screen-readers, which will still read out the content of you leave this off

Then show it when you need it?




回答3:


The DOM must be load before you can access and modify it properly using JavaScript. You should use CSS to hide the elements and then later when the DOM has finished loading you´ll be able to show then as you like.




回答4:


Use CSS to hide element:

display:none;



来源:https://stackoverflow.com/questions/8516911/is-there-any-event-jquery-or-javascript-where-can-i-hide-elements-before-they-ap

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