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

javascript - Hiding the contents of DIV - Stack Overflow

programmeradmin2浏览0评论

I have a DIV with a script as shown below

<div style="text-align:center">
                <script type='text/javascript' language='JavaScript' src='.mysite'></script>
</div>

What I want is that the users should not be able to see this div on the site, but the script should be executed as in the normal way. Please suggest!

I have a DIV with a script as shown below

<div style="text-align:center">
                <script type='text/javascript' language='JavaScript' src='http://xslt.alexa./site_stats/js/t/a?url=www.mysite.'></script>
</div>

What I want is that the users should not be able to see this div on the site, but the script should be executed as in the normal way. Please suggest!

Share Improve this question asked Mar 27, 2009 at 4:48 KJaiKJai
Add a ment  | 

7 Answers 7

Reset to default 11

I am not sure what it is you are including with that Javascript call, but if you want to hide the contents of this DIV just add this to the style declaration: display: none;

Check out the CSS display documentation.

EDIT: The SCRIPT inside the DIV tag will still get loaded, which I believe is the desired effect.

Just change your style to

<div style="text-align:center; display: none;">
                <script type='text/javascript' language='JavaScript' src='http://xslt.alexa./site_stats/js/t/a?url=www.mysite.'></script>
</div>

Give your div a meaningful name.

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

The in the CSS add the

.hidden {
    display: none;
}

When you want to make an element hidden from the user, set the css proper "display: none;"

You have to style your div with this code:

<div style="text-align:center; display: none; visibility: hidden;">
  <!-- other code -->
</div>

This is the way the mozilla team works, if I remember well.

If the JavaScript generates html code that you don't want to be visible you can write some specific styles to make these auto generated elements hidden without making your outer div hidden. Eg if the JavaScript generates a div and fills it with content then you could do something like this:

The HTML:

div id="hideinside">
                <script type='text/javascript' language='JavaScript' src='http://xslt.alexa./site_stats/js/t/a?url=www.mysite.'></script>
</div>

The CSS:

#hideinside div {
    display:none; /* hides all divs inside your outer div */
}
div.hidden {
   position: absolute;
   left: 10000px;
}
发布评论

评论列表(0)

  1. 暂无评论