Created
June 5, 2018 20:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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