Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing JQuery to traverse DOM structure, finding a specific <table> element located after HTML 'comment'
    text
    copied!<p>I currently have a website source code (no control over the source) which contains certain content that needs to be manipulated. This would be simple on the surface, however there is no unique ID attribute on the tag in question that can uniquely identify it, and therefore allow for further traversal.</p> <p>Here is a snippet of the source code, surrounding the tag in question.</p> <pre><code> ... &lt;td width="100%"&gt; &lt;!--This table snaps the content columns(one or two)--&gt; &lt;table border="0" width="100%"&gt; ... </code></pre> <p>Essentially, the HTML comment stuck out as an easy way to gain access to that element. Using the <a href="http://www.bennadel.com/index.cfm?dax=blog:1563.view" rel="nofollow noreferrer">JQuery comment add-on</a> from <a href="https://stackoverflow.com/questions/1623734/selecting-html-comments-with-jquery">this question</a>, <a href="https://stackoverflow.com/questions/2911053/using-jquery-to-traverse-dom-structure-finding-a-specific-table-element-locate/2911152#2911152">and some help from snowlord comment below</a>, I have been able to identify the comment and retrieve the following output using the 'dump' extension.</p> <pre><code>$('td').comments().filter(":contains('This table snaps the content columns(one or two)')").dump(); </code></pre> <p>returns;</p> <pre><code>jQuery Object { 0 = DOMElement [ nodeName: DIV nodeValue: null innerHTML: [ 0 = String: This table snaps the content columns(one or two) ] ] } </code></pre> <p>However I am not sure how to traverse to the sibling element in the DOM.</p> <p>This should be simple, but I haven't had much selector experience with JQuery. Any suggestions are appreciated.</p>
 

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