JQuery Error ?? How to get the first "td" in all visible lines

I have a table and I hide a few rows. I want to get the first td in all displayed lines. I have the following statement

$("table.SimpleTable tbody tr:visible td:first-child"); 

does this work in firefox but not in IE any ideas?

+7
javascript jquery
source share
4 answers

I am running the code on the click event. The html you wrote is quite a lot, but for some reason unknown to me, it does not work. However, I found a job. (I'm trying to get a comma delimited string from all the values ​​in the first td for visible strings). In any case, the next work will be done.

  var notfirst = false; var serials = ""; var tds = $("table.SimpleTable tbody tr:visible td:first-child"); for (var i = 0; i < tds.length; i++) { var td = $(tds[i]); if (td.is(":hidden")) continue; if (notfirst) serials += ","; else notfirst = true; serials += $.trim(td.text()); } 

For some reason: the hidden tag is working correctly, but not: visible in IE7

+6
source share

That should work. With HTML that looks like this:

 <table class='SimpleTable'> <tr style='display: none;'> <td>test1</td> </tr> <tr> <td>test2</td> </tr> <tr> <td>test3</td> </tr> <tr style='display: none;'> <td>test4</td> </tr> <tr> <td>test5</td> </tr> <tr> <td>test6</td> </tr> </table> 

Performing this action:

 $("table.SimpleTable tbody tr:visible td:first-child").css('color','red'); 

Makes red for me in Firefox, IE7. What does your HTML look like?

Here is what I tested above on

EDIT . It is very strange to me that you need to do what you are doing right now. You should be able to replace what you have right now:

 var serials = []; $("table.SimpleTable tbody tr:visible td:first-child").each(function() { serials.push($.trim($(this).text())); }); var serials = serials.join(','); 

If TDs are populated from the selector, they should only be visible. If you pick up hidden TDs in TV shows (which, I must emphasize, really shouldn't happen and is an error or an error sign somewhere), try this selector:

 $("table.SimpleTable tbody tr:not(:hidden) td:first-child") 
+6
source share

From the documentation:

"How: apparently, the calculation is changed in jQuery 1.3.2. An element is considered visible if it and its parents are wasting space in the document. CSS visibility is not accepted."

Perhaps this has something to do with it. Try using a class selector or something instead of tr: visible

+3
source share

why don't you break it up a bit?

 $("table.SimpleTable").find("tr:visible").find("td:first-child").text() 

?

+3
source share

All Articles