Skip to content

Instantly share code, notes, and snippets.

@ryankinal
Created April 23, 2012 17:26
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 ryankinal/2472492 to your computer and use it in GitHub Desktop.
Save ryankinal/2472492 to your computer and use it in GitHub Desktop.
Silly .NET developer
/** I need a function for some stuff **/
function GetParentOfType(element, type) {
if (element == null)
return null
while (element.nodeName != type) {
if (element.parentElement == null) {
return null;
}
element = element.parentElement;
}
return element;
}
/** lulz overload **/
function GetParentOfTypes(element, type1, type2) {
if (element == null)
return null
while (element.nodeName != type1 && element.nodeName != type2) {
if (element.parentElement == null) {
return null;
}
element = element.parentElement;
}
return element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment