How can we help you today?

How to Open a Specific Accordions Item Upon Page Load

When you add an Accordions Design Element to your SharePoint page, all accordion sections will automatically start in a collapsed (closed) state when users first load the page:


Accordions default state


This article shows you how to keep a specific ShortPoint Accordion item open when the page is loaded:


accordion item automatically opens


TABLE OF CONTENTS


Prerequisites


sample Accordions


Step-by-Step Tutorial

Choose the environment you’re using and follow the steps under it:


For Microsoft 365 / SharePoint 2019 / SharePoint SE

This is for users who have the Microsoft 365 / SharePoint 2019 / SharePoint Subscription Edition (SE) environment.

Below is the JavaScript code used in the interactive tutorial:


function ShortPointReady() {
  var $ = shortpoint.base.libs.$;
  var $openItemHeader = $('.auto-open-item .shortpoint-toggle-header');
  var $openItemContent = $('.auto-open-item .shortpoint-toggle-content');
  var $openItemOpenIcon = $('.auto-open-item .shortpoint-toggle-icon-close');
  $openItemOpenIcon
    .removeClass(function(index, className) {
    return (className.match (/(^|\s)shortpoint-icon-fa-\S+/g) || []).join(' ')})
    .addClass('shortpoint-icon-fa-minus-square-o');
  $openItemHeader
    .removeClass('shortpoint-close')
    .addClass('shortpoint-open sp-inserter-open');
  $openItemContent
    .removeClass('shortpoint-close')
    .addClass('shortpoint-open sp-inserter-open');
  shortpoint.initWithin( $openItemContent.parent(), function() {
    $openItemContent.css({
      height: $openItemContent.children().outerHeight()});
  });
};
  
// only run when we're not in edit mode
if( !window.shortPointInserter ) {
  setTimeout( ShortPointReady , 1000);
}

Step 1: Edit the ShortPoint Web Part

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


Edit

  • Close the Toolbox:


close icon


  • Click the Edit Properties icon:


Edit properties icon


Step 2: Edit the Accordions Design Element


NOTEBefore proceeding, you must already have an Accordions Design Element on your page. If you don’t have it yet, check out How to Customize the Accordions Design Element.


  • Click the Accordions tag:


Accordions Design Element


  • Hover over the item you want to open upon page load and click the cogwheel icon:

cogwheel icon


Step 3: Add a Class Name

  • Go to the Custom CSS tab.
  • Write ‘auto-open-item’ as the class name:


class name


  • Click the green check mark.

Step 4: Copy the Code

  • Copy the JavaScript code below:
function ShortPointReady() {
  var $ = shortpoint.base.libs.$;
  var $openItemHeader = $('.auto-open-item .shortpoint-toggle-header');
  var $openItemContent = $('.auto-open-item .shortpoint-toggle-content');
  var $openItemOpenIcon = $('.auto-open-item .shortpoint-toggle-icon-close');
  $openItemOpenIcon
    .removeClass(function(index, className) {
    return (className.match (/(^|\s)shortpoint-icon-fa-\S+/g) || []).join(' ')})
    .addClass('shortpoint-icon-fa-minus-square-o');
  $openItemHeader
    .removeClass('shortpoint-close')
    .addClass('shortpoint-open sp-inserter-open');
  $openItemContent
    .removeClass('shortpoint-close')
    .addClass('shortpoint-open sp-inserter-open');
  shortpoint.initWithin( $openItemContent.parent(), function() {
    $openItemContent.css({
      height: $openItemContent.children().outerHeight()});
  });
};
  
// only run when we're not in edit mode
if( !window.shortPointInserter ) {
  setTimeout( ShortPointReady , 1000);
}

Step 5: Add the Code Design Element

  • Click the plus icon to open the library of Design Elements:


plus icon

  • Look for Code and select it:


code


Step 6: Paste the Code

  • Paste the code in the JavaScript field:


paste code


  • Go to the Design tab.
  • Disable Sandbox Mode:


Sandbox Mode


  • Click the green check mark.

Step 7: Save and Publish

  • Save your changes:


Save

  • Publish your page:


Publish


That’s it! Now, when you reload the page, the Accordions item you’ve edited will automatically open:


accordion item automatically opens


For SharePoint 2013 and 2016

Copy the JavaScript code below and follow the steps in How to Add JavaScript code to a Page using the Script Editor Web Part to learn how to add it.


<script type="text/javascript">(function() {'use strict';/*** hook method to be executed as soon as shortpoint* rendered on the page*/function ShortPointReady() {            var $ = shortpoint.base.libs.$;            var $openItemHeader = $('.auto-open-item .shortpoint-toggle-header');            var $openItemContent = $('.auto-open-item .shortpoint-toggle-content');            var $openItemOpenIcon = $('.auto-open-item .shortpoint-toggle-icon-close');            $openItemOpenIcon                .removeClass(function(index, className) {                    return (className.match (/(^|\s)shortpoint-icon-fa-\S+/g) || []).join(' ')                })                .addClass('shortpoint-icon-fa-minus-square-o');            $openItemHeader.removeClass('shortpoint-close').addClass('shortpoint-open sp-inserter-open');            $openItemContent.removeClass('shortpoint-close').addClass('shortpoint-open sp-inserter-open');            shortpoint.initWithin( $openItemContent.parent(), function() {                $openItemContent.css({                    height: $openItemContent.children().outerHeight()                });            });};// shortpoint not yet available in the page// wait for shortpoint render dom eventdocument.addEventListener( 'shortpoint-render-above-fold', function() {// exit on edit modeif( window.shortPointInserter ) {return;}setTimeout( ShortPointReady , 500);});})();</script>



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 95 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