Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Get the max value from array - divi modules

const mainBlog = document.querySelector('.main_blg')
      if (mainBlog != null || mainBlog != undefined) {
        let titleHeights = []
        let contentHeights = []
        const root = document.querySelector(':root');
        const articles = mainBlog.querySelectorAll('article')

        if (articles.length > 0) {
          articles.forEach(article => {
            const title = article.querySelector('.entry-title')
            const content = article.querySelector('.post-content-inner')
            titleHeights.push(title.clientHeight)
            contentHeights.push(content.clientHeight)
          })

          const maxTitle = titleHeights.reduce((a, b) => {
            return Math.max(a, b)
          });
          const maxContent = contentHeights.reduce((a, b) => {
            return Math.max(a, b)
          });

          root.style.setProperty('--title-height', `${maxTitle}px`);
          root.style.setProperty('--content-height', `${maxContent}px`);
        }
      }
 
PREVIOUS NEXT
Tagged: #Get #max #array #divi #modules
ADD COMMENT
Topic
Name
7+5 =