Skip to content

Instantly share code, notes, and snippets.

@elliottregan
Created June 5, 2018 20:27
Show Gist options
  • Save elliottregan/dadd87116b2c31514d10b6e231fcd991 to your computer and use it in GitHub Desktop.
Save elliottregan/dadd87116b2c31514d10b6e231fcd991 to your computer and use it in GitHub Desktop.
Print out all `<meta>` tags as an array. Use it to collect meta tag information
const allMetaTags = [];
document.querySelectorAll('meta').forEach(el => {
const meta = {};
[...el.attributes].forEach(attr => {
if (attr.name === 'name') {
Object.assign(meta, {
name: attr.value,
});
}
else if (attr.name === 'property') {
Object.assign(meta, {
property: attr.value,
});
}
else if (attr.name === 'content') {
Object.assign(meta, {
content: attr.value,
});
}
});
if (meta.content) {
allMetaTags.push(meta);
}
});
console.log(allMetaTags);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment