It seems elements selected using :contains(sub)
with sub
containing <
or >
cannot get to their parents.
The following example should illustrate the problem I'm having in both Safari and Camino (Gecko on Mac):
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
</head>
<body>
<p><strong>bar</strong></p>
<p><strong><foo></strong></p>
<script type="text/javascript">
alert($('body strong:contains("bar")').length);
alert($('body strong:contains("bar")').parent().length);
alert($('body strong:contains("<foo>")').length);
alert($('body strong:contains("<foo>")').parent().length); // this fails
alert($('body strong').length);
alert($('body strong').parent().length); // two p elements
alert($('body strong').parent().parent().length); // one body
</script>
</body>
</html>
Output is:
1
1
1
0
2
2
1
Any ideas why the fourth one is 0
instead of 1
, or how I can circumvent this?
This page mentions escaping names in selectors, but that didn't work either (also, I'm not sure if it's applicable).