How can we help you today?

How to Hide Any Element Inside the Embedded SharePoint Web Part Design Element

This article will provide you with a JavaScript code that you can modify to hide elements on your embedded SharePoint web part.


For example, you can hide the background of an embedded web part:


Before


before with background


After


After with hidden background


TABLE OF CONTENTS


Prerequisites


Step-by-step Tutorial

Follow the steps below to learn how to hide elements of your embedded SharePoint web part:


Step 1: Edit the SharePoint web part


Go to the SharePoint page you want to use and click Edit:


Edit


Click the cross icon to close the Toolbox:


cross icon


Click the ShortPoint tag:


ShortPoint tag


Select the edit properties icon:


edit properties icon


Step 2: Copy and modify the JavaScript code


NOTEBefore proceeding, make sure you already have a SharePoint web part Design Element on your page. Check out How to Embed a SharePoint Web Part into ShortPoint to learn how to add it to your page.

before with background


Copy the code below:


(function(){
  const myInterval = setInterval(function () {
    const iframeElement = document.querySelector('iframe[id^="sharepoint-webpart-shortpoint"]');
    if (iframeElement != null) {
      const iframeDoc = iframeElement.contentDocument || elem.contentWindow.document;
      if (iframeDoc != null) {
        iframeElement.setAttribute("allowtransparency", "true") 
        clearInterval(myInterval);
        iframeDoc.querySelector("head").insertAdjacentHTML(
          "beforeend",
          `<style type="text/css">

                #sideNavBox, 
                #suiteBarDelta, 
                #s4-titlerow, 
                .ms-core-sideNavBox-removeLeftMargin { 
                    display: none !important; 
                } 

                #contentBox {
                    margin-left: 10px; 
                    margin-right: 10px; 
                }

            </style>`
        );
      }
    }
  }, 2000);
})()


Edit the code that's in the middle of this snippet (between <style type="text/css"> and </style>) according to what you need to accomplish. For example, we want to turn the background of the embedded web part completely transparent, so we modified the code to look like the one below:


(function(){
  const myInterval = setInterval(function () {
    const iframeElement = document.querySelector('iframe[id^="sharepoint-webpart-shortpoint"]');
    if (iframeElement != null) {
      const iframeDoc = iframeElement.contentDocument || elem.contentWindow.document;
      if (iframeDoc != null) {
        iframeElement.setAttribute("allowtransparency", "true") 
        clearInterval(myInterval);
        iframeDoc.querySelector("head").insertAdjacentHTML(
          "beforeend",
          `<style type="text/css">

                  body, .CanvasZone, .ControlZone  {
                      background-color: transparent !important;
                  }

           </style>`
        );
      }
    }
  }, 2000);
})()


Step 3: Insert the Code Design Element


Click the plus icon to open the Library of Design Elements:


plus icon


Use the search bar to look for Code and select it:


Code


Step 4: Paste the code


Pate the modified code in the JavaScript field:


paste code


Navigate to the Design tab:


Design tab


Make sure that [1] Sandbox Mode is disabled and click the [2] green check mark:


sandbox mode and green check mark


Step 5: Save


Click the eye icon to see your page in real-time:


eye icon


Click Save to apply all your changes:


Save


That’s it! You can now use the JavaScript code provided to hide elements of embedded SharePoint web parts.


Related articles:

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

World's best intranet sites are designed using ShortPoint

Get started today! Learn more
See all 74 topics

Start a trial

Ignite your vision. Install ShortPoint directly on your site, or play in sandbox mode. No credit card required.

Get started today

World’s best intranet sites are designed using ShortPoint

Thousands of companies using ShortPoint everyday to design, brand and build award winning intranet sites.

Get started Learn more