I have a pretty simple dynamic html table structure containing links and the possibility that it will contain a second table with links. I would like to change the html attribute for the links in the main table, but not in the second.
My structure:
<table>
<tr><td><a href="www.google.com">link</a></td></tr>
<tr><td><a href="www.google.com">link</a></td></tr>
<tr><td><a href="www.google.com">link</a></td></tr>
<tr><td><a href="www.google.com">link</a></td></tr>
<tr><td><a href="www.google.com">link</a></td></tr>
<tr>
<td>
<table>
<tr><td><a href="http://stackoverflow.com">link</a></td></tr>
<tr><td><a href="http://stackoverflow.com">link</a></td></tr>
<tr><td><a href="http://stackoverflow.com">link</a></td></tr>
</table>
</td>
</tr>
So, for example, I would like to change all hrefs from "www.google.com" to "www.foo.com". I can change the href attribute, but I am having problems with my b / c selector when there is a time when the second table will not exist.
My current selector is as follows: $('table a').filter(':not(table:last a)')
I'm sure this is not the most efficient way to do this, but it worked until the second table entered the game.
source
share