There's a small error in it that if ctx is undefined it does nothing.
really should be...
...since your defining ctx on the next line anyway.
Also, if you care about speed how about using matches/matchSelector, its alot faster.....
http://jsperf.com/closestagain
...and according to caniuse available in all modern browser except Opera Mini.
Oh, and thanks for making this, Ive looked a few times for something like this that doesnt use JQuery and this is the first thing thats ever popped up....well done.
EDIT: Actually I take the speed thing back as I just tested it in FF and yours won. I have a bad habit of only testing in Chrome because its the only browser I code for.
There's a small error in it that if ctx is undefined it does nothing.
really should be...
...since your defining ctx on the next line anyway.
Also, if you care about speed how about using matches/matchSelector, its alot faster.....
http://jsperf.com/closestagain
...and according to caniuse available in all modern browser except Opera Mini.
Oh, and thanks for making this, Ive looked a few times for something like this that doesnt use JQuery and this is the first thing thats ever popped up....well done.
EDIT: Actually I take the speed thing back as I just tested it in FF and yours won. I have a bad habit of only testing in Chrome because its the only browser I code for.