tags:

views:

104

answers:

6

I have the following code:

<%-- other tags --%>
<table>
  <tr width="100%">
    <td width="130" />
    <td id="BottomCell" width="100%" />
  </tr>
  <tr>
    <td/>
    <td/>
  </tr>
</table>
<%-- other tags --%>

There may be more than one table on the page. I want the td before "BottomCell" to be removed (or hidden) when the page is loaded. How can I do this with javascript or css?

Thanks.

BTW, I'm developing a Sharepoint WebPart that will be put onto a page. The is on that page, which i don't have control of directly. But the WebPart should remove this as long as it shows up on the page.

+1  A: 

tr > td should do the trick.

Child and Sibling selectors

http://css-tricks.com/child-and-sibling-selectors/

adamwstl
Thanks. I may have more than one tr, and only in one of the tr I want to remove a td
Bryan
+4  A: 

In jQuery:

$('#BottomCell').prev().detach();
James Thomas
Haven't tried JQuery, but I assume this should work. Thanks! :)
Bryan
+4  A: 

Wow, going back to basics after using a framework is hard work.

var element = document.getElementById('BottomCell').previousSibling;
var parent = element.parentNode;
parent.removeChild(element);
Diodeus
If it is, then you didn't learn the basics in the first place. ;)
Bob
No, it's just all the damn typing.
Diodeus
I applied your approach and it works perfectly. I use the code for window.onload event. It seems the tr is removed after the page has been rendered. So I see some jagged movements. Any idea on how to solve this?
Bryan
@bryan: just don't add your column to your code? what's the point in adding it anyway?
knittl
@knittl, I've explained why in the end of the question. Thanks.
Bryan
@Bryan, well, since the title of this posting includes "without id", my approach tried to accomplish that without the use of an id, but since you used the id anyway, it begs the question why you wouldn't just use the id on the first cell and remove it that way. In any case, all id's on a page need to be unique, else you can't be sure which element you'll get if you use document.getElementById
Bob
+1  A: 

@diodeus if there are only 2 data cells that would be acceptable, however if you wish to remove the first data cell regardless of however many cells are located in that row, you can do something like

var el = document.getElementById('BottomCell');
el.removeChild(el.parentNode.firstChild);
boogyman
+1  A: 

Well, assuming you have only one table, then you could do something like this (in javascript):

var firstCell = document.getElementsByTagName('tr')[0].getElementsByTagName('td')[0];
firstCell.parentNode.removeChild(firstCell);

It would get the first cell of the first row in the entire DOM tree, and remove that cell.

Bob
though it's not necessary that it's the first tr in the document.
Bryan
+1  A: 

In jQuery I would find the parent and use the :first selector probably

RichardBlizzard