Cookie Consent by Free Privacy Policy Generator

Enhance On-Page Assessments with Custom Headings Display

Go to the Best Of the SEO Community.

Kyle Faber
Kyle Faber
Oct 31, 2024, 7:47 PM
 
For those of you doing on-page assessments, here’s a simple script that you can save as a bookmark to make headings appear on the page.
 
Chrome extensions work, but I like this better when visually scanning and scrolling.
 
  const headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
  headings.forEach(heading => {
    const tagName = heading.tagName;
    const prefixText = `[${tagName}] `;
    const firstChild = heading.firstChild;
    const isSpan = firstChild && firstChild.nodeType === Node.ELEMENT_NODE && firstChild.tagName === 'SPAN';
    const hasPrefix = isSpan && firstChild.textContent.trim() === prefixText.trim();
    if (!hasPrefix) {
      const prefixSpan = document.createElement('span');
      prefixSpan.textContent = prefixText;
      prefixSpan.style.background = '#ff0000';      // Red background
      prefixSpan.style.padding = '10px';            // 10px padding
      prefixSpan.style.color = '#fff';              // White text color
      prefixSpan.style.marginRight = '10px';        // 10px right margin
      prefixSpan.style.borderRadius = '3px';        // 3px border-radius
      heading.insertBefore(prefixSpan, firstChild);
    }
  });
})();```
And here it is in bookmark format:
Forwarded thread from another channel:
Andy Drinkwater
Andy Drinkwater
Nov 1, 2024, 5:24 AM
Very nice! I’ll have a look later :) thank you.
Anne Berlin
Anne Berlin
Nov 1, 2024, 10:00 AM
ooh, that' *is* a useful way to see them! no dumb questions: how does one bookmark a scriptlet like that?
Kyle Faber
Kyle Faber
Nov 1, 2024, 11:05 AM
@anne.berlin Take the bookmark code above and when creating the bookmark, set the name (I called mine “Save Headings”) and the URL (URL = the code above)
Anne Berlin
Anne Berlin
Nov 1, 2024, 11:13 AM
ok that was simple. thank you!