views:

77

answers:

2
<table id="experiences" cellpadding="0" border="1" width="100%">
    <caption>table name</caption>
    <tr><th>col1</th><th>col2</th><th>col3</th><th>col4</th><th>col5</th><th>col6</th></tr>
    <tr><td>something</td><td>something</td><td>something</td><td>something</td><td>something</td><td>something</td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</table>

Like the above,the target row should be the third row from the top.

BTW,I'm not fimiliar with jQuery, $().eq(0) selects the first one,

how to exclude the first one?

Will $().ne(0) work?

A: 

This should do it:

function not_just_nbsp() {
    return $(this).html() !== "#nbsp;";
}

$("#experiences td").filter(not_just_nbsp).filter(":first").parent();

Just replace the # in nbsp with an ampersand &. Had to do it like that to make it display here on StackOverflow.

Magnar
I don't understand your code,will it select out the third row as a final result?
Shore
Will this detect more than 1 whitespace in columns?
rahul
It finds all the table cells, filters out those with just a space in them, selects the last of the remaining cells, and finds the parent table row. In your example it will select the second tr on line 4.
Magnar
@phoenix: If you want to rule out all table cells with only whitespace (as opposed to those with one  ) you can use a regexp in the filter function instead.
Magnar
why you use $(this).html() !== " "; instead of $(this).html() !== " "?
Shore
For the same reason they don't show up in your example: StackOverflow won't show them. Tried fixing it now.
Magnar
Oh I see..Another question,why you use .filter(":last")?Shouldn't it be .filter(":first")?
Shore
What if there is no matching row?
Shore
If there are no matching rows, that means there are no rows with anything in them, and you get an empty result.
Magnar
you say "empty result",you mean its boolean value is false?
Shore
tried,seems not.then how to judge whether the result is empty or not?
Shore
A: 

To select all rows greater than the first row, you can do:

$('#experiences td:gt(0)')
Jason
Seems it's wrong,right?
Shore
no, it's correct: http://docs.jquery.com/Selectors/gt#index
Jason
$('.yourClass').gt(0)$('.yourClass:gt(0)') are the same ?
Shore
gah sorry... it's late here. fixed.
Jason