SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know the JavaScript for setting display:none on an empty web part zone? I remember seeing it once on a publishing site but now can't find it.

This is to avoid the padding and spacing a web part zone displays when there is no web part added to it.

share|improve this question
up vote 1 down vote accepted

WSS 3 web part pages has TD's containing the WebPartZones and those TD's have a name and id which is _invisibleIfEmpty. Then each page contains a javascript like this:

<script language="javascript">if(typeof(MSOLayout_MakeInvisibleIfEmpty) == "function") {MSOLayout_MakeInvisibleIfEmpty();}</script>

The MSOLayout_MakeInvisibleIfEmpty function makes them invisible...


share|improve this answer

Somehow, MSOLayout_... did not work out for me, so I wrote the following jQuery code which works as well and also checks if there is only a menu inside that cell before it hides it.

$('[name="_invisibleIfEmpty"]').filter(function () {
    return $.trim($(this).html()).length == 0 || $(this).children("menu").length;
share|improve this answer

Or, as SharePoint Publishing Page Layout puts it:

<SharePointWebControls:ScriptBlock runat="server">
if(typeof(MSOLayout_MakeInvisibleIfEmpty) == &quot;function&quot;) 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.