1

I find the solution a bit tricky and I need some help with this. Let's say we have 3 HTML DOM elements, how can we find the closest element that contains all this 3 elements? Is there any efficient way to achieve this?

I am using C# .net and classic System.Windows.Forms webbrowser called webBrowser1.

If the question sounds a bit hard, let me explain. We have the following HTML text:

<body>
<div id="a">
  <div id="b">some text</div>
  <div id="c">some text</div>
  <div id="d"> 
      <div id="e">some text</div>
      <div id="f">
           <div id="g">some text</div>
      </div>
  </div>
</div>
</body>

The first element that contains elements B C and E is A

The first element that contains G and E is D

Really hope somebody can help with this. Thank you in advance

BlasterGod
  • 196
  • 1
  • 13
  • Oh man `:(` I'd love to write this in JavaScript, but it's tagged C#. – Šime Vidas May 30 '12 at 01:30
  • well I think I could translate to C#, as long as you can write in Javascript and using DOM it should be good :) – BlasterGod May 30 '12 at 01:46
  • In that case, check out the answer [here](http://stackoverflow.com/questions/3960843/how-to-find-the-nearest-common-ancestors-of-two-or-more-nodes). – Mark Reed May 30 '12 at 04:01
  • OK, I'll write the JavaScript-solution later today (in ~8 hours) (I got work do do now). – Šime Vidas May 30 '12 at 11:26
  • The solution from: http://stackoverflow.com/questions/3960843/how-to-find-the-nearest-common-ancestors-of-two-or-more-nodes does help. But I find it a bit unefficient if you have an variable number of elements (not only 2). But it will do for now, thank you – BlasterGod May 30 '12 at 17:53
  • More help on the issue would be appreciated. I can't seem to figure out an efficient way to achieve this. The idea is that I can have more than 2 nodes, and I need to find the common ancestor (the first node that contains all the other nodes) for all this nodes. – BlasterGod Jun 06 '12 at 20:21

0 Answers0