views:

96

answers:

2

Not sure if I've just missed something but this doesn't work:

$(this).children('td.threadtitle a').html('thread title');

However this does

$(this).children('td.threadtitle').children('a').html('thread title');

I'm just trying to understand why this is occuring. But is this a bug?

A: 
  1. Should work. Can you upload some code so we can see your html?
  2. Just a note: If you want children, you should use "td.threadtitle > a". Otherwhise it should be find('a').
Kobi
+3  A: 

The selector argument to .children is a filter. $(this).children('td.threadtitle a') finds nodes which match the selector td.threadtitle a and are direct children of this. Assuming that your threadtitle tds are inside of this, and not above or equal to it, this situation will never happen.

I think that what you might really be looking for is a contextualized selector:

$('td.threadtitle a', this).html("Thread title")

which finds things that match that selector as long as they occur anywhere under this.

hobbs
The only way $(this).children('td.threadtitle a') would work is if $(this) is <td class="threadtitle">.
cpharmston
I believe you are correct - the filter of `children` should not go another level down. Nice catch.
Kobi