Note that there are some explanatory texts on larger screens.

plurals
  1. POGet all html between two elements
    primarykey
    data
    text
    <p>Problem:<br> Extract all html between two headers including the headers html. The header text is known, but not the formatting, tag name, etc. They are not within the same parent and might (well, almost for sure) have sub children within it's own children).</p> <p>To clarify: headers could be inside a <code>&lt;h1&gt;</code> or <code>&lt;div&gt;</code> or any other tag. They may also be surrounded by <code>&lt;b&gt;</code>, <code>&lt;i&gt;</code>, <code>&lt;font&gt;</code> or more <code>&lt;div&gt;</code> tags. The key is: the only text within the element is the header text.</p> <p>The tools I have available are: C# 3.0 utilizing a WebBrowser control, or Jquery/Js.</p> <p>I've taken the Jquery route, traversing the DOM, but I've ran into the issue of children and adding them appropriately. Here is the code so far:</p> <pre><code>function getAllBetween(firstEl,lastEl) { var collection = new Array(); // Collection of Elements var fefound =false; $('body').find('*').each(function(){ var curEl = $(this); if($(curEl).text() == firstEl) fefound=true; if($(curEl).text() == lastEl) return false; // need something to add children children // otherwise we get &lt;table&gt;&lt;/table&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;tr&gt;&lt;/tr&gt; etc if (fefound) collection.push(curEl); }); var div = document.createElement("DIV"); for (var i=0,len=collection.length;i&lt;len;i++){ $(div).append(collection[i]); } return($(div).html()); } </code></pre> <p>Should I be continueing down this road? With some sort of recursive function checking/handling children, or would a whole new approach be better suited?</p> <p>For the sake of testing, here is some sample markup:</p> <pre><code>&lt;body&gt; &lt;div&gt; &lt;div&gt;Start&lt;/div&gt; &lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Oops&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;div&gt; &lt;div&gt;End&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Any suggestions or thoughts are greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload