ms-vh2 exists by verifying "view source" but I cant get the following code to do the tricks for me. any idea??

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $("tr.ms-viewheadertr th:contains('Name')").css("width", "315px");
    //$("TH.ms-vh2:contains('Name')").css("width", "50px");
    //$("TH.ms-vh2-nograd:contains('Title')").css("width", "350px");
    //$("TH.ms-vh2:contains('LongDescription')").css("width", "350px");

The selector is working for me. Try this to see if the selector is working for you:

$("th.ms-vh2:contains('Name')").css("background-color", "red");  

It might be that your selector is working, but the css seems like it isn't. What I mean by this is that I can't reduce the width of the <th> to 1px because the content that it contains won't allow it to be that small.

  • Red background works. However, no matter what i put 1px or 1000 px it does not change. i think ootb css overwrites the width piece. Oct 19 '11 at 19:40
  • I guess Marc is right . endusersharepoint.com/STP/viewtopic.php?f=13&t=959 You're adjusting the table header cell (TH), but not the table detail cells (TDs) below them. The widest cell usually wins. Oct 19 '11 at 20:00
  • I was able to adjust the width, but was not able to make it that small. Check out this article. blogs.msdn.com/b/saurabhkv/archive/2009/06/22/… You can use the _spBodyOnLoadFunctionNames.push method to ensure the body of the document has loaded before your JQuery runs.
    – Panter
    Oct 19 '11 at 20:10
  • I thank you for trying this for me and find a solution. But this did not work for me. <script language="javascript"> _spBodyOnLoadFunctionNames.push("FunctionName"); function FunctionName() { // Code } </script> Oct 20 '11 at 13:48
  • Actually, I turned on the developer tools for IE and I get an error on this line _spBodyOnLoadFunctionNames.push('ColumnWidth'); I tried _spBodyOnLoadFunctionNames.push("ColumnWidth"); but same error Oct 20 '11 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.