Skip to content

Instantly share code, notes, and snippets.

@apbassi89
Last active September 12, 2016 18:59
Show Gist options
  • Select an option

  • Save apbassi89/e4bce1527f468e71093af2aecfabd576 to your computer and use it in GitHub Desktop.

Select an option

Save apbassi89/e4bce1527f468e71093af2aecfabd576 to your computer and use it in GitHub Desktop.
/**
* Performs a "mini" heading audit of a webpage.
* The page must have jQuery loaded in order for this script to work
*/
function auditHeadings() {
var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
console.log("===== STARTING HEADING AUDIT =====")
jQuery.each(headings, function (key, selector) {
var headingsEl = jQuery(selector);
if (!headingsEl.length) {
console.log(">>> You don't have any <" + selector + "> tags on this page!");
} else {
console.log(">>> You have " + headingsEl.length + " <" + selector + "> tags on this page!");
headingsEl.each(function (key, el) {
console.log(
el,
jQuery.trim(jQuery(el).text().replace(/\s\s+/g, ' '))
);
});
}
});
};
auditHeadings();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment