Chris Benoit. Christopher Michael Benoit (French pronunciation: â; May 21, 1967 â June 24, 2007) was a Canadian professional wrestler.
The problem. Say you have a website (site A) with an iframe wherein you host another website (site B). In old and unsecure browsers it was possible to do a JavaScript call from site B to site A like this: window.parent.doSomething(); Here the doSomething function is living on site A and is called by site B through its parent window.
This does the trick: function findAncestor (el, cls) { while ((el = el.parentElement) && !el.classList.contains(cls)); return el; } The while loop waits until el has the desired class, and it sets el to el's parent every iteration so in the end, you have the ancestor with that class or null. Here's a fiddle, if anyone wants to improve it. It won't work on old browsers (i.e. IE); see this compatibility table for classList.