Last active
February 8, 2017 17:25
-
-
Save horacioibrahim/d53b4be5453df5cc7d98 to your computer and use it in GitHub Desktop.
Get parent
This file contains hidden or 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
| _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