public static IHTMLElement GetAncestor(this IHTMLElement e, string tagName) { for (e = e.parentElement; e != null; e = e.parentElement) { if (e.IsTag(tagName)) { return(e); } } return(e); }