This is another post in my on-going series on how to use jQuery with SharePoint.
If you want to learn more about jQuery, I highly recommend: jQuery in Action by Bear Bibeault and Yehuda Katz.
UPDATE (already!): I did think of a better way to locate the <TR> tag I want to hide and wrote about it here. You may still find this article interesting anyway so I’m leavnig it up.
I want to hide a text field, “Hide Me!” as shown:
The following jQuery does the trick for me:
The code is saying, “find me all input fields whose title = Hide Me!. Then, get its parent and then next parent and the *next* parent (phew!) and invoke the hide() method on that thing, whatever it happens to be.
I figured out that parent structure by viewing the HTML for the form that SharePoint created as shown:
<TD nowrap="true" valign="top" width="190px" class="ms-formlabel">
<TD valign="top" class="ms-formbody" width="400px">
<!-- FieldName="Hide Me!"
This picture shows the same, but marked up with the parents:
The first parent (1) is a span tag. Span’s parent (2) is a TD tag and then finally we get to the real parent I want to hide (3) which is the TR tag itself.
This is a pretty terrible approach I think because it’s extremely dependent on the very specific structure of this form. When SharePoint 2010 comes out, this whole structure could change and break this approach. What I really want to do is craft a jQuery selector that is along the lines of “find me all the TR’s (and only TR tags) that have somewhere in their child elements an input field whose title = Hide Me!”. I starting from the bottom and moving up. Assuming I figure this out, I’ll post an updated “quick and easy’ post.
Subscribe to my blog.
Follow me on Twitter at http://www.twitter.com/pagalvin