Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

3 Answers

up vote 0 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...

/WW

share|improve this answer
add comment

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;
}).hide();
share|improve this answer
add comment

Or, as SharePoint Publishing Page Layout puts it:

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

Your Answer

 
discard

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.