Using JQuery to traverse DOM structure, finding a specific <table> element located after HTML 'comme
Posted
by Shadow
on Stack Overflow
See other posts from Stack Overflow
or by Shadow
Published on 2010-05-26T07:57:16Z
Indexed on
2010/05/26
9:41 UTC
Read the original article
Hit count: 281
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.
Here is a snippet of the source code, surrounding the tag in question.
...
<td width="100%">
<!--This table snaps the content columns(one or two)-->
<table border="0" width="100%">
...
Essentially, the HTML comment stuck out as an easy way to gain access to that element. Using the JQuery comment add-on from this question, and some help from snowlord comment below, I have been able to identify the comment and retrieve the following output using the 'dump' extension.
$('td').comments().filter(":contains('This table snaps the content columns(one or two)')").dump();
returns;
jQuery Object {
0 = DOMElement [
nodeName: DIV
nodeValue: null
innerHTML: [
0 = String: This table snaps the content columns(one or two)
]
]
}
However I am not sure how to traverse to the sibling element in the DOM.
This should be simple, but I haven't had much selector experience with JQuery. Any suggestions are appreciated.
© Stack Overflow or respective owner