Last active
December 27, 2015 05:59
-
-
Save nanzono/7278684 to your computer and use it in GitHub Desktop.
html要素を取得
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
var titles = document.getElementsByTagName("title"); | |
var title = (titles.length > 0) ? titles[0].innerHTML: ""; | |
var metas = document.getElementsByTagName("meta"); | |
var description = ""; | |
var keywords = ""; | |
for (i=0; i<metas.length; i++){ | |
var meta_name = metas[i].getAttribute("name"); | |
if (meta_name=="description"){ | |
description = metas[i].getAttribute("content"); | |
} else if (meta_name=="keywords"){ | |
keywords = metas[i].getAttribute("content"); | |
} | |
} | |
var h1s = document.getElementsByTagName("h1"); | |
var h1 = (h1s.length > 0) ? h1s[0].innerHTML : ""; | |
console.log("title: " + title); | |
console.log("description: " + description); | |
console.log("keywords: " + keywords); | |
console.log("h1: " + h1); | |
console.log("h1 is " + h1s.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment