Skip to content

Instantly share code, notes, and snippets.

@ryck
Created April 21, 2011 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryck/934422 to your computer and use it in GitHub Desktop.
Save ryck/934422 to your computer and use it in GitHub Desktop.
Get tag by rel attribute
function getElementByRel(rel) {
aElements = document.getElementsByTagName("link");
relElems = [];
for (i = 0; i < aElements.length; i++) {
if (aElements[i].hasAttribute("rel") && aElements[i].rel == rel) {
return aElements[i];
}
}
}
tag = getElementByRel('author');
alert(tag.href);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment