How to hide specific webpart

Jyoti Rajpurohit 21 Reputation points
2023-09-28T16:56:28.49+00:00

Hi,

we have multiples webparts on page. so we have requirement to hide specific webpart.

How can we hide webpart on basis of condition or help of query string?

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 51,941 Reputation points Microsoft External Staff
    2023-09-29T08:08:33.4066667+00:00

    You could use JS codes to hide a specific webpart. Here are steps:

    1.Click Edit page in the Settings gear.

    2.Add a web part, choose Script Editor web part.

    3.Press F12, find the webpart ID.

    1

    4.Edit web part, then click EDIT SNIPPET, add following codes, replace the webpart ID with your own.

    <script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("hide");
    function hide()
    {
    document.getElementById("MSOZoneCell_WebPartWPQ2").style.display='none';
    }
    </script>
    

    5.Save the page.

    For conditionally hide, please follow below article:

    https://stackoverflow.com/questions/13704978/hide-webpart-based-on-sharepoint-list-value


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.