Skip to content

Instantly share code, notes, and snippets.

@horacioibrahim
Last active February 8, 2017 17:25
Show Gist options
  • Select an option

  • Save horacioibrahim/d53b4be5453df5cc7d98 to your computer and use it in GitHub Desktop.

Select an option

Save horacioibrahim/d53b4be5453df5cc7d98 to your computer and use it in GitHub Desktop.
Get parent
_getParent: function(el, queryCssClass) {
var p = el.parentNode; // It's can be parent...
var classList = el.classList;
// sure that the parent not go to itself
is_owner = classList.contains(queryCssClass);
if (is_owner) {
return ;
}
// avoid node empty
while (p !== null) {
var o = p;
if (o.classList.contains(queryCssClass)) {
return o
}
// moving up for more above element.
p = o.parentNode;
}
return undefined; // returns an Array []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment